-
Notifications
You must be signed in to change notification settings - Fork 4
/
Bucket.bt
89 lines (81 loc) · 2.49 KB
/
Bucket.bt
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
// -*- mode: c;-*-
#define BUCKET_TYPE uint64
#define BUCKET_SIZE 0xFFFF
local BUCKET_TYPE __bucket[BUCKET_SIZE] = {0};
void ClearBucket(){
local uint64 i;
for( i = 0; i < BUCKET_SIZE; i++ ){
__bucket[i] = 0;
}
}
void Bucket(BUCKET_TYPE value){
__bucket[value] += 1;
}
// are you analyzing whether or not something is a bitfield?
// use this: http://bitwisecmd.com/
// type in all the found numbers and visualize the bits
// the following will automatically give you a url with
// all unique values
// a cheap way to increase the effectiveness of this sort
// of analysis would be to comment out surrounding vars
// and throw in some dummy ones bitfielded to the correct width
// to narrow the scope of the variable you supply to Bucket()
// e.g.
/*
ushort alignment1 : 3;
ushort toBucket : 4;
ushort alignment2 : 9;
*/
void ReportBucket(){
local uint64 i;
local BUCKET_TYPE max_index = 0;
local BUCKET_TYPE min_index = BUCKET_SIZE;
local string bitwise = "http://bitwisecmd.com/#";
local string nbitwise = bitwise;
for( i = 0; i < BUCKET_SIZE; i++){
if( __bucket[i] > 0 ){
//Printf("INDEX #%d: %d > 0\n", i, __bucket[]);
if( i > max_index ){
max_index = i;
}
if( i < min_index ){
min_index = i;
}
}
}
// below is an experimental sort, it ruins everything because
// I don't know how to retain key indexes
/*
local uint64 j;
local BUCKET_TYPE a;
local uint64 order[BUCKET_SIZE] = {0};
Printf("FUCK: %d\n", __bucket[0]);
Printf("BUCKET: MIN/MAX = %d/%d\n", min_index, max_index);
for (i = min_index; i <= max_index; i++){
for (j = i + 1; j <= max_index; j++){
if (__bucket[i] > __bucket[j]){
a = __bucket[i];
__bucket[i] = __bucket[j];
__bucket[j] = a;
} else {
order[i] = i;
}
}
}
for( i = 0; i <= BUCKET_SIZE; i++ ){
if( __bucket[order[i]] > 0 ){
Printf("BUCKET: VALUE 0x%04LX HAPPENED %d TIME(S)!\n", i, __bucket[order[i]]);
}
}
*/
for( i = min_index; i <= max_index; i++ ){
if( __bucket[i] > 0 ){
Printf("BUCKET: VALUE 0x%04LX HAPPENED %d TIME(S)!\n", i, __bucket[i]);
SPrintf( nbitwise, "%s0x%04LX,", nbitwise, i);
}
}
if( bitwise != nbitwise ){
Printf("%s\n", nbitwise);
CopyStringToClipboard(bitwise);
}
}