Post: Canonical Hash String [C#/VB.NET/C++]
02-11-2016, 07:55 PM #1
Sonoro
I like anteaters
(adsbygoogle = window.adsbygoogle || []).push({}); This is the method that Black Ops 3 engine uses to hash strings in the game.
The game uses this method to hash data such as dvar names and script function names. :laim:

C#
    internal unsafe static int CanonicalHash(string fname)
{
string x = fname + "\0";
fixed(char* c = x)
{
int hash = (char.ToLower(*c) ^ 0x4B9ACE2F) * 0x1000193;
for (int z = 1; z < x.Length; z++)
hash = (char.ToLower(x[z]) ^ hash) * 0x1000193;
return hash;
}
return 0;
}


VB
    Friend Shared Function CanonicalHash(fname As String) As Integer
Dim x As String = fname & Convert.ToString(vbNullChar)
Dim hash As Integer = (Char.ToLower(c.Target) Xor &H4b9ace2f) * &H1000193
For z As Integer = 1 To x.Length - 1
hash = (Char.ToLower(x(z)) Xor hash) * &H1000193
Next
Return hash

Return 0
End Function


C++
    int CanonicalHash(const char* str)
{
int hash = (tolower(*str) ^ 0x4B9ACE2F) * 0x1000193;
for (size_t i = 1; i <= strlen(str); i++)
hash = (tolower(str[i]) ^ hash) * 0x1000193;
return hash;
}
(adsbygoogle = window.adsbygoogle || []).push({});

The following 5 users say thank you to Sonoro for this useful post:

Sabotage, gοd, OG Trojan041, Rick, VenoxCoding
02-12-2016, 09:29 AM #2
Python
Bebe Snek
Originally posted by xSonoro View Post
This is the method that Black Ops 3 engine uses to hash strings in the game.
The game uses this method to hash data such as dvar names and script function names.

C#
    internal unsafe static int CanonicalHash(string fname)
{
string x = fname + "\0";
fixed(char* c = x)
{
int hash = (char.ToLower(*c) ^ 0x4B9ACE2F) * 0x1000193;
for (int z = 1; z < x.Length; z++)
hash = (char.ToLower(x[z]) ^ hash) * 0x1000193;
return hash;
}
return 0;
}


VB
    Friend Shared Function CanonicalHash(fname As String) As Integer
Dim x As String = fname & Convert.ToString(vbNullChar)
Dim hash As Integer = (Char.ToLower(c.Target) Xor &H4b9ace2f) * &H1000193
For z As Integer = 1 To x.Length - 1
hash = (Char.ToLower(x(z)) Xor hash) * &H1000193
Next
Return hash

Return 0
End Function


C++
    int CanonicalHash(const char* str)
{
int hash = (tolower(*str) ^ 0x4B9ACE2F) * 0x1000193;
for (size_t i = 1; i <= strlen(str); i++)
hash = (tolower(str[i]) ^ hash) * 0x1000193;
return hash;
}


Reply
02-12-2016, 09:31 AM #3
OfficialJesseP
It is what it is.
Originally posted by xSonoro View Post
This is the method that Black Ops 3 engine uses to hash strings in the game.
The game uses this method to hash data such as dvar names and script function names.

C#
    internal unsafe static int CanonicalHash(string fname)
{
string x = fname + "\0";
fixed(char* c = x)
{
int hash = (char.ToLower(*c) ^ 0x4B9ACE2F) * 0x1000193;
for (int z = 1; z < x.Length; z++)
hash = (char.ToLower(x[z]) ^ hash) * 0x1000193;
return hash;
}
return 0;
}


VB
    Friend Shared Function CanonicalHash(fname As String) As Integer
Dim x As String = fname & Convert.ToString(vbNullChar)
Dim hash As Integer = (Char.ToLower(c.Target) Xor &H4b9ace2f) * &H1000193
For z As Integer = 1 To x.Length - 1
hash = (Char.ToLower(x(z)) Xor hash) * &H1000193
Next
Return hash

Return 0
End Function


C++
    int CanonicalHash(const char* str)
{
int hash = (tolower(*str) ^ 0x4B9ACE2F) * 0x1000193;
for (size_t i = 1; i <= strlen(str); i++)
hash = (tolower(str[i]) ^ hash) * 0x1000193;
return hash;
}

Very useful release Sonoro. I'm interested to see where this goes from here Smile
02-12-2016, 09:32 AM #4
Rick
Splicer
Originally posted by Python View Post
Reply


Vivid post python can you explain this way with words you have.
02-13-2016, 04:40 PM #5
You must login or register to view this content.
You must login or register to view this content.

Good job on crediting your source, lol
02-13-2016, 04:49 PM #6
SC58
Former Staff
The function name is called 'SL_GetCanonicalString'


Here some other hashing the game does if anyone want them.
02-13-2016, 04:59 PM #7
Originally posted by SC58 View Post
The function name is called 'SL_GetCanonicalString'


Lol, no sir that is a function that is present within the BO series, the algorithm is real and has a usage outside of call of duty (like all cryptography does), my reversing is not from that function either, a secondary function exists to be used within the DemonWare class for a secondary usage (client -> server), it also is a re-written version with optimised code. Good to see you're still on here though, lol.
02-13-2016, 05:01 PM #8
SC58
Former Staff
Originally posted by Bitwise View Post
Lol, no sir that is a function that is present within the BO series, the algorithm is real and has a usage outside of call of duty (like all cryptography does), my reversing is not from that function either, a secondary function exists to be used within the DemonWare class for a secondary usage (client -> server), it also is a re-written version with optimised code. Good to see you're still on here though, lol.


good to see u here wanting credit lol

btw that function is in every cod :p

The following user thanked SC58 for this useful post:

Sabotage
02-13-2016, 05:17 PM #9
Sabotage
Gaming Squad
Originally posted by SC58 View Post
good to see u here wanting credit lol

btw that function is in every cod :p


Bitwise is one hell of a guy...
02-13-2016, 05:32 PM #10
Originally posted by SC58 View Post
good to see u here wanting credit lol

btw that function is in every cod :p


I don't want credit, I gave it to the owner of the 7s thread for that purpose; the credited source would be 7s, not me. I never stated it wasn't in every cod, why do you have to keep trying to out-do people when all your "research" is nothing but pseudo code from PDB's and PC, lmao.

Originally posted by Sabotage View Post
Bitwise is one hell of a guy...


Indeed, indeed.

The following user thanked Bitwise for this useful post:

primetime43

Copyright © 2026, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo