SHOW:
|
|
- or go back to the newest paste.
| 1 | #6SXPT91-595B | |
| 2 | #include <stdio.h> | |
| 3 | #include <string.h> | |
| 4 | #include <time.h> | |
| 5 | ||
| 6 | #define mystr "My own utility. Copyright (C) 2007-2010 hpgl, Russia" | |
| 7 | ||
| 8 | #define allow595B | |
| 9 | #define allowA95B | |
| 10 | #define allow2A7B | |
| 11 | ||
| 12 | #define fSVCTAG 0 | |
| 13 | #define fHDDSN 1 | |
| 14 | #define fHDDold 2 | |
| 15 | #define t595B 0 | |
| 16 | #define tD35B 1 | |
| 17 | #define tA95B 2 | |
| 18 | #define t2A7B 3 | |
| 19 | ||
| 20 | #ifdef allow595B | |
| 21 | #define f595B | |
| 22 | #endif | |
| 23 | #ifdef allowA95B | |
| 24 | #define f595B | |
| 25 | #endif | |
| 26 | #ifdef allow2A7B | |
| 27 | #define f595B | |
| 28 | #endif | |
| 29 | ||
| 30 | char bSuffix[]="595BD35BA95B2A7B"; | |
| 31 | ||
| 32 | char scancods[]="\00\0331234567890-=\010\011qwertyuiop[]\015\377asdfghjkl;'`\377\\zxcvbnm,./"; | |
| 33 | char encscans[]={0x05,0x10,0x13,0x09,0x32,0x03,0x25,0x11,0x1F,0x17,0x06,0x15, \
| |
| 34 | 0x30,0x19,0x26,0x22,0x0A,0x02,0x2C,0x2F,0x16,0x14,0x07,0x18, \ | |
| 35 | 0x24,0x23,0x31,0x20,0x1E,0x08,0x2D,0x21,0x04,0x0B,0x12,0x2E}; | |
| 36 | ||
| 37 | #ifdef allow2A7B | |
| 38 | char chartabl2A7B[72]="012345679abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0"; | |
| 39 | #endif | |
| 40 | ||
| 41 | unsigned int MD5magic[64]={
| |
| 42 | 0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee, | |
| 43 | 0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501, | |
| 44 | 0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be, | |
| 45 | 0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821, | |
| 46 | 0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa, | |
| 47 | 0xd62f105d, 0x02441453, 0xd8a1e681, 0xe7d3fbc8, | |
| 48 | 0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed, | |
| 49 | 0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a, | |
| 50 | 0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c, | |
| 51 | 0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70, | |
| 52 | 0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x4881d05, | |
| 53 | 0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665, | |
| 54 | 0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039, | |
| 55 | 0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1, | |
| 56 | 0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1, | |
| 57 | 0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391}; | |
| 58 | ||
| 59 | unsigned char inData[23],outData[16]; | |
| 60 | char buf1output[32], buf1input[20]; | |
| 61 | char bug4; | |
| 62 | ||
| 63 | void calcsuffix(char bfunc, char btype, char *outbuf); | |
| 64 | ||
| 65 | void initData(void) {
| |
| 66 | *(int *)(&outData[0]) =0x67452301; | |
| 67 | *(int *)(&outData[4]) =0xEFCDAB89; | |
| 68 | *(int *)(&outData[8]) =0x98BADCFE; | |
| 69 | *(int *)(&outData[12])=0x10325476; | |
| 70 | } | |
| 71 | ||
| 72 | typedef int (encfuncT1) (int num1, int num2, int num3); | |
| 73 | ||
| 74 | #ifdef f595B | |
| 75 | int enc0F2(int num1, int num2, int num3) {return (((~num3 ^ num2) & num1) ^ ~num3);}
| |
| 76 | int enc0F4(int num1, int num2, int num3) {return (( ~num2 ^ num1) ^ num3); }
| |
| 77 | int enc0F5(int num1, int num2, int num3) {return (( ~num1 | ~num3) ^ num2); }
| |
| 78 | #endif | |
| 79 | int enc1F2(int num1, int num2, int num3) {return ((( num3 ^ num2) & num1) ^ num3);}
| |
| 80 | int enc1F4(int num1, int num2, int num3) {return (( num2 ^ num1) ^ num3); }
| |
| 81 | int enc1F5(int num1, int num2, int num3) {return (( num1 | ~num3) ^ num2); }
| |
| 82 | int encF3 (int num1, int num2, int num3) {return ((( num1 ^ num2) & num3) ^ num2);}
| |
| 83 | ||
| 84 | typedef int (encfuncT2)(encfuncT1 func, int num1, int num2, int num3, int key); | |
| 85 | ||
| 86 | int enc1F1 (encfuncT1 func, int num1, int num2, int num3, int key) | |
| 87 | {
| |
| 88 | return func(num1,num2,num3)+key; | |
| 89 | } | |
| 90 | ||
| 91 | #ifdef f595B | |
| 92 | int enc0F1 (encfuncT1 func, int num1, int num2, int num3, int key) | |
| 93 | {
| |
| 94 | return func(num1,num2,num3)-key; | |
| 95 | } | |
| 96 | #endif | |
| 97 | ||
| 98 | unsigned int rol(unsigned int t, int bitsrot) | |
| 99 | {
| |
| 100 | return (t >> (32-bitsrot)) | (t << bitsrot); | |
| 101 | } | |
| 102 | ||
| 103 | void blockEncodeF(int *outdata, int *encblock, encfuncT2 func1, | |
| 104 | encfuncT1 func2, encfuncT1 func3, encfuncT1 func4, encfuncT1 func5 ) | |
| 105 | {
| |
| 106 | char S[4][4] = {{ 7, 12, 17, 22 },{ 5, 9, 14, 20 },{ 4, 11, 16, 23 },{ 6, 10, 15, 21 }};
| |
| 107 | int A,B,C,D,t,i; | |
| 108 | ||
| 109 | A=outdata[0]; | |
| 110 | B=outdata[1]; | |
| 111 | C=outdata[2]; | |
| 112 | D=outdata[3]; | |
| 113 | ||
| 114 | for (i=0;i<64;i++) { t=MD5magic[i]; switch (i>>4) {
| |
| 115 | case 0: t=A+func1(func2,B,C,D, t+encblock[(i) & 15]); break; | |
| 116 | case 1: t=A+func1(func3,B,C,D, t+encblock[(i*5+1) & 15]); break; | |
| 117 | case 2: t=A+func1(func4,B,C,D, t+encblock[(i*3+5) & 15]); break; | |
| 118 | case 3: t=A+func1(func5,B,C,D, t+encblock[(i*7) & 15]); break; | |
| 119 | } | |
| 120 | A=D; D=C; C=B; B+=rol(t,S[i>>4][i&3]); | |
| 121 | }; | |
| 122 | ||
| 123 | outdata[0]+=A; | |
| 124 | outdata[1]+=B; | |
| 125 | outdata[2]+=C; | |
| 126 | outdata[3]+=D; | |
| 127 | } | |
| 128 | ||
| 129 | void blockEncode(char *outdata, int *encblock, char btype) {
| |
| 130 | if (btype==tD35B) | |
| 131 | blockEncodeF((int *)outdata,encblock,enc1F1,enc1F2,encF3,enc1F4,enc1F5); | |
| 132 | #ifdef f595B | |
| 133 | else | |
| 134 | blockEncodeF((int *)outdata,encblock,enc0F1,enc0F2,encF3,enc0F4,enc0F5); | |
| 135 | #endif | |
| 136 | } | |
| 137 | ||
| 138 | void encode(char *inbuf,int cnt,char btype) {
| |
| 139 | int encBlock[16]; | |
| 140 | char *ptr; | |
| 141 | initData(); | |
| 142 | memcpy(encBlock,inbuf,cnt); | |
| 143 | ptr=&((char *)encBlock)[cnt]; | |
| 144 | *ptr++=0x80; | |
| 145 | memset(ptr,0,64-1-cnt); | |
| 146 | encBlock[16-2]=((unsigned int)cnt << 3); | |
| 147 | blockEncode(outData,encBlock,btype); | |
| 148 | } | |
| 149 | ||
| 150 | void psw(char bfunc, char btype, char *outbuf) {
| |
| 151 | int cnt,i,lenpsw,r; | |
| 152 | if (bfunc==fHDDold) {
| |
| 153 | memcpy(inData,buf1input,11); | |
| 154 | // calcsuffix(bfunc,btype,outbuf); | |
| 155 | for (cnt=0;cnt<8;cnt++) outbuf[cnt]= scancods[ outbuf[cnt] ]; } else { memset(inData,0,sizeof(inData)); if (bfunc==fSVCTAG) cnt=7; else cnt=11; if ((bfunc==fHDDSN) && (btype==tA95B)) memcpy(inData,&buf1input[3],cnt-3); else memcpy(inData,buf1input,cnt); if (btype==t595B) memcpy(&inData[cnt],&bSuffix[0],4); else if (btype==tD35B) memcpy(&inData[cnt],&bSuffix[4],4); else if (btype==tA95B) memcpy(&inData[cnt],&bSuffix[0],4); else if (btype==t2A7B) memcpy(&inData[cnt],&bSuffix[12],4); cnt += 4; inData[cnt] = inData[4] & 0x1F; inData[cnt+1] = ((inData[4] >> 5) | (((inData[3] >> 5) | (inData[3] << 3)) & 0xF1) & 0x1F); inData[cnt+2] = ((inData[3] >> 2) & 0x1F);
| |
| 156 | inData[cnt+3] = (inData[3] >> 7) | ((inData[2] << 1) & 0x1F); inData[cnt+4] = (inData[2] >> 4) | ((inData[1] << 4) & 0x1F); inData[cnt+5] = (inData[1] >> 1) & 0x1F; | |
| 157 | inData[cnt+6] = (inData[1] >> 6) | ((inData[0] << 2) & 0x1F); inData[cnt+7] = (inData[0] >> 3) & 0x1F; | |
| 158 | for (i=cnt;i<8+cnt;i++) {
| |
| 159 | r = 0xAA; | |
| 160 | if (inData[i] & 1) | |
| 161 | r ^= inData[4]; | |
| 162 | if (inData[i] & 2) | |
| 163 | r ^= inData[3]; | |
| 164 | if (inData[i] & 4) | |
| 165 | r ^= inData[2]; | |
| 166 | if (inData[i] & 8) | |
| 167 | r ^= inData[1]; | |
| 168 | if (inData[i] & 16) | |
| 169 | r ^= inData[0]; | |
| 170 | inData[i] = encscans[r % sizeof(encscans)]; | |
| 171 | } | |
| 172 | cnt = 23; | |
| 173 | encode(inData,cnt,btype); | |
| 174 | r = outData[0] % 9; | |
| 175 | lenpsw = 0; | |
| 176 | for (cnt=0;cnt<16;cnt++) {
| |
| 177 | if ((r <= cnt) && (lenpsw<8)) { buf1output[lenpsw++] = scancods[encscans[outData[cnt] % sizeof(encscans)]]; } } } } int main(int argc, char *argv[]) { unsigned char len,len1,bfunc,eol=1,echo=0, *minus,s2[20]; signed char btype; int argn=0; if (argc>1)
| |
| 178 | echo=1; | |
| 179 | ||
| 180 | if (!echo) | |
| 181 | fputs("" mystr "\n" \
| |
| 182 | "Short service tag should be right padded with '*' up to length 7 chars\n" \ | |
| 183 | "HDD serial number is right 11 chars from real HDDSerNum left padded with '*'\n" \ | |
| 184 | "Some BIOSes has left pad HDD serial number with spaces instead '*'\n",stdout); | |
| 185 | ||
| 186 | while (!feof(stdin)) {
| |
| 187 | if ((argc<=1) && argn) break; fputs("Input: #",stdout); if (argc>1) {
| |
| 188 | strncpy(buf1input,argv[++argn],sizeof(buf1input));argc--; | |
| 189 | } | |
| 190 | else {
| |
| 191 | if (!eol) while (!feof(stdin) && (fgetc(stdin)!='\n')); eol=0; | |
| 192 | if (fgets(buf1input,16+1+1,stdin)==NULL) {
| |
| 193 | if (echo) fputs("\n",stdout);
| |
| 194 | break; | |
| 195 | } | |
| 196 | } | |
| 197 | len=strlen(buf1input); | |
| 198 | if (len && (buf1input[len-1]=='\n')) {len--;eol=1;buf1input[len]=0;}
| |
| 199 | if (echo) {fputs(buf1input,stdout);fputs("\n",stdout);}
| |
| 200 | minus=strchr(buf1input,'-'); | |
| 201 | if (len==11) {
| |
| 202 | if (minus!=NULL) {
| |
| 203 | fputs("- Incorrect input\n",stdout);
| |
| 204 | continue; | |
| 205 | } | |
| 206 | bfunc=fHDDold; | |
| 207 | fputs("By HDD serial number for older BIOS: ",stdout);
| |
| 208 | } else {
| |
| 209 | if (len==0) break; | |
| 210 | if (minus==NULL) {
| |
| 211 | fputs("- No BIOS type found in input string, must be followed by -595B and other registered\n",stdout);
| |
| 212 | continue; | |
| 213 | } | |
| 214 | len1=minus-(unsigned char*)buf1input; | |
| 215 | ||
| 216 | btype=-1; | |
| 217 | #ifdef allow595B | |
| 218 | if (strncmp(&buf1input[len1+1],&bSuffix[0],4)==0) btype=t595B; | |
| 219 | else | |
| 220 | #endif | |
| 221 | if (strncmp(&buf1input[len1+1],&bSuffix[4],4)==0) btype=tD35B; | |
| 222 | else | |
| 223 | #ifdef allowA95B | |
| 224 | if (strncmp(&buf1input[len1+1],&bSuffix[8],4)==0) btype=tA95B; | |
| 225 | else | |
| 226 | #endif | |
| 227 | #ifdef allow2A7B | |
| 228 | if (strncmp(&buf1input[len1+1],&bSuffix[12],4)==0) btype=t2A7B; | |
| 229 | #endif | |
| 230 | if (btype<0) {
| |
| 231 | fputs("- Invalid service tag in input string, allowed only -D35B and other registered\n",stdout);
| |
| 232 | continue; | |
| 233 | } | |
| 234 | struct tm *time1; time_t timer1=time(NULL); | |
| 235 | time1=gmtime(&timer1); | |
| 236 | strftime(s2,sizeof(s2),"%d.%m.%Y %H:%M",time1); | |
| 237 | fputs(s2,stdout); | |
| 238 | fputs(" DELL ",stdout);
| |
| 239 | ||
| 240 | if (len1==7) {
| |
| 241 | bfunc=fSVCTAG; | |
| 242 | fputs("service tag: ",stdout);
| |
| 243 | fputs(buf1input,stdout); | |
| 244 | } else | |
| 245 | if (len1==11) {
| |
| 246 | bfunc=fHDDSN; | |
| 247 | fputs("HDD serial number: ",stdout);
| |
| 248 | fputs(buf1input,stdout); | |
| 249 | } | |
| 250 | else {
| |
| 251 | fputs("- Incorrect input, must be 7 chars service tag or 11 chars HDD serial number\n",stdout);
| |
| 252 | continue; | |
| 253 | } | |
| 254 | } | |
| 255 | psw(bfunc,btype,buf1output); | |
| 256 | fputs(" password: ",stdout);
| |
| 257 | fputs(buf1output,stdout); | |
| 258 | if (bug4) fputs(" !bug4 warning - password may not work!",stdout);
| |
| 259 | ||
| 260 | if (btype==t595B) if (bfunc==fSVCTAG) { //to check if A95B bug
| |
| 261 | char mpw1[20]; | |
| 262 | strcpy(mpw1,buf1output); | |
| 263 | psw(bfunc,tA95B,buf1output); | |
| 264 | if (strcmp(mpw1,buf1output)!=0) {
| |
| 265 | fputs(" passwordA95B: ",stdout);
| |
| 266 | fputs(buf1output,stdout); | |
| 267 | } | |
| 268 | } | |
| 269 | fputs("\n",stdout);
| |
| 270 | } | |
| 271 | return 0; | |
| 272 | } |