-
Notifications
You must be signed in to change notification settings - Fork 0
/
neshash.c
103 lines (86 loc) · 1.99 KB
/
neshash.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
//
// code to calc the "hash" on nes/snes mini settings file
//
// snes mini
// the hash over: "/var/lib/clover/profiles/0/home-menu/save/system-save.json/data"
// is stored in: "/var/lib/clover/profiles/0/home-menu/save/system-save.json/hash"
//
// nes mini
// the hash over: "/var/lib/clover/profiles/0/home-menu/save/system-save.json"
// is stored in: "/var/lib/clover/profiles/0/home-menu/save/system-save.json.hash"
//
// xorloser - feb 1028
//
#include <stdio.h>
#include <stdlib.h>
typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned int u32;
typedef unsigned long long u64;
u64 g_table[256] = {0};
int g_table_is_setup = 0;
void hash_table_setup()
{
for(int i=0; i<256; i++)
{
u64 val = i;
for(int j=0; j<8; j++)
{
if( val & 1 )
{
val = val >> 1;
val ^= 0xD800000000000000ULL;
}
else
{
val >>= 1;
}
}
g_table[i] = val;
}
}
u64 hash_process(u8* pData, u32 dataSize)
{
u32 i;
u64 hash;
if( !g_table_is_setup )
{
hash_table_setup();
g_table_is_setup = 1;
}
hash = 0;
for(i=0; i<dataSize; i++)
{
hash = g_table[ (hash ^ pData[i])&0xFF ] ^ (hash >> 8);
}
return hash;
}
int main(int argc, char* argv[])
{
if( argc != 2 )
{
printf("neshash v1.0 - xorloser feb 2018\n");
printf("Usage: neshash <data filename>\n");
return 1;
}
const char* p_filename = argv[1];
FILE* fd = fopen(p_filename, "rb");
if( fd == NULL )
{
printf("Error opening %s\n", p_filename);
return 2;
}
fseek(fd, 0, SEEK_END);
int data_size = ftell(fd);
fseek(fd, 0, SEEK_SET);
u8* p_data = malloc(data_size);
fread(p_data, 1, data_size, fd);
// we don't print a newline character here because the 'hash' files
// don't have any newline character in them, so this way we can put
// the output directly into the hash file.
u64 hash = hash_process(p_data, data_size);
printf("%016llX", hash);
fclose(fd);
free(p_data);
return 0;
}