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 | program keygenme; uses Windows,Messages,CommCtrl; {$R software.RES} var WinClass: TWndClassA; Inst: HINST; hWindow: HWND; TheMessage: TMsg; hDrive:HWND; hID:HWND; hf:THandle; htitle:HWND; cmbChange: HWND; cmbAbout: HWND; cmbExit: HWND; PaintStruct: TPaintStruct; PaintDC: HDC; hFont1: HFONT; isNT:Boolean; function StrToInt(const S: string):Integer; var E: Integer; begin Val(S, Result, E); end; |
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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 | function toString(Value: Integer): string; var f,x:integer; str:string; begin f:=value; repeat x:=f and $F; case (x) of $0..$9: str:=char($30+x)+str; $A..$F: str:=char($37+x)+str; end; if length(str)=4 then str:='-'+str; f:=f shr 4; until length(str)=9; toString:=str; end; function FillSerial(buf,Num:dword):integer; asm push esi mov esi,eax //eax=buf //edx=Serial push edx xor eax,eax @@FAT32: inc eax mov edx,[esi+$52] xor edx,$33544146 jnz @@FAT movzx edx,byte ptr[esi+$56] xor edx,$32 jnz @@FAT pop edx mov [esi+$43],edx//FAT32 jmp @@exit @@FAT: inc eax mov edx,[esi+$36] and edx,$00FFFFFF xor edx,$544146 jnz @@NTFS pop edx mov [esi+$27],edx jmp @@exit @@NTFS: inc eax mov edx,[esi+3] xor edx,$5346544E//NTFS jnz @@Error pop edx mov [esi+$48],edx//NTFS jmp @@exit @@Error: inc eax pop edx @@exit: pop esi end; function LockDisk(DriverNum:dword;levelx:byte;Permissions:word):Boolean; var reg:record reg_EBX:DWORD; reg_EDX:DWORD; reg_ECX:DWORD; reg_EAX:DWORD; reg_EDI:DWORD; reg_ESI:DWORD; reg_Flags:DWORD; end; pok:dword; isOK:Boolean; begin reg.reg_EAX:=$440D; reg.reg_EBX:=levelx*256+DriverNum; reg.reg_ECX:=$484A; reg.reg_EDX:=Permissions; reg.reg_EDI:=0; reg.reg_ESI:=0; reg.reg_Flags:=0; isOK:=DeviceIoControl(hf, 1, @reg, sizeOf(reg), @reg, sizeOf(reg), pok, nil); isOK:=isOK and (not odd(reg.reg_Flags)); if (not isOK) then begin reg.reg_EAX:=$440D; reg.reg_EBX:=levelx*256+DriverNum; reg.reg_ECX:=$084A; reg.reg_EDX:=Permissions; reg.reg_Flags:=0; isOK:=DeviceIoControl(hf, 1, @reg, sizeOf(reg), @reg, sizeOf(reg), pok, nil); isOK:=isOK and (not odd(reg.reg_Flags)); end; LockDisk:=isOK; end; function UnLockDisk(DriverNum:dword):Boolean; var reg:record reg_EBX:DWORD; reg_EDX:DWORD; reg_ECX:DWORD; reg_EAX:DWORD; reg_EDI:DWORD; reg_ESI:DWORD; reg_Flags:DWORD; end; pok:dword; isOK:Boolean; begin reg.reg_EAX:=$440D; reg.reg_EBX:=DriverNum; reg.reg_ECX:=$486A; reg.reg_EDX:=0; reg.reg_EDI:=0; reg.reg_ESI:=0; reg.reg_Flags:=0; isOK:=DeviceIoControl(hf, 1, @reg, sizeOf(reg), @reg, sizeOf(reg), pok, nil); isOK:=isOK and (not odd(reg.reg_Flags)); if (not isOK) then begin reg.reg_EAX:=$440D; reg.reg_EBX:=DriverNum; reg.reg_ECX:=$086A; reg.reg_Flags:=0; isOK:=DeviceIoControl(hf, 1, @reg, sizeOf(reg), @reg, sizeOf(reg), pok, nil); isOK:=isOK and (not odd(reg.reg_Flags)); end; UnLockDisk:=isOK; end; function HardRWV1(DriverNum:dword;pBuf:dword;rw:dword):Boolean; var reg:record reg_EBX:DWORD; reg_EDX:DWORD; reg_ECX:DWORD; reg_EAX:DWORD; reg_EDI:DWORD; reg_ESI:DWORD; reg_Flags:DWORD; end; diskio:packed record dwStartSector:DWORD; // 要读写的起始扇区号 wSectors:WORD; // 要读写的扇区数 dwBuffer:DWORD; end; pok:dword; isOK:Boolean; begin diskio.dwStartSector:=0; diskio.wSectors:=1; diskio.dwBuffer:=dword(pBuf); reg.reg_EAX:=DriverNum-1; reg.reg_EBX:=DWORD(@diskio); reg.reg_ECX:=$FFFF; reg.reg_EDX:=0; reg.reg_EDI:=0; reg.reg_ESI:=0; reg.reg_Flags:=0; isOK:=DeviceIoControl(hf, rw, //2:read,3:write @reg, sizeOf(reg), @reg, sizeOf(reg), pok, nil); isOK:=isOK and (not odd(reg.reg_Flags)); HardRWV1:=isOK; end; function HardRWV2(DriverNum:dword;pBuf:dword;rw:dword):Boolean; var reg:record reg_EBX:DWORD; reg_EDX:DWORD; reg_ECX:DWORD; reg_EAX:DWORD; reg_EDI:DWORD; reg_ESI:DWORD; reg_Flags:DWORD; end; diskio:packed record dwStartSector:DWORD; // 要读写的起始扇区号 wSectors:WORD; // 要读写的扇区数 dwBuffer:DWORD; end; pok:dword; isOK:Boolean; begin diskio.dwStartSector:=0; diskio.wSectors:=1; diskio.dwBuffer:=dword(pBuf); reg.reg_EAX:=$7305; reg.reg_EBX:=DWORD(@diskio); reg.reg_ECX:=$FFFF; reg.reg_EDX:=DriverNum; reg.reg_EDI:=0; reg.reg_ESI:=rw; //6001:write,0:read reg.reg_Flags:=0; isOK:=DeviceIoControl(hf, 6, @reg, sizeOf(reg), @reg, sizeOf(reg), pok, nil); isOK:=isOK and (not odd(reg.reg_Flags)); HardRWV2:=isOK; end; function ReadHardSec(DriverNum:dword;pBuf:dword):Boolean; var VerInfo:_OSVERSIONINFOA; isOK:Boolean; begin GetVersionExA(VerInfo); if VerInfo.dwBuildNumber > $438 then isOK:=HardRWV2(DriverNum,pBuf,$0) else isOK:=HardRWV1(DriverNum,pBuf,$2); ReadHardSec:=isOK; end; function WriteHardSec(DriverNum:dword;pBuf:dword):Boolean; var VerInfo:_OSVERSIONINFOA; isOK:Boolean; begin GetVersionExA(VerInfo); if VerInfo.dwBuildNumber > $438 then isOK:=HardRWV2(DriverNum,pBuf,$6001) else isOK:=HardRWV1(DriverNum,pBuf,$3); WriteHardSec:=isOK; end; function FloppySecRW(DriverNum:dword;pBuf:dword;rw:dword):Boolean; var reg:record reg_EBX:DWORD; reg_EDX:DWORD; reg_ECX:DWORD; reg_EAX:DWORD; reg_EDI:DWORD; reg_ESI:DWORD; reg_Flags:DWORD; end; pok:dword; isOK:Boolean; begin reg.reg_EAX:=rw*256+1; //ah=02:read,ah=03:write reg.reg_EBX:=DWORD(pBuf); reg.reg_ECX:=1; reg.reg_EDX:=DriverNum-1; reg.reg_EDI:=0; reg.reg_ESI:=0; reg.reg_Flags:=1; isOK:=DeviceIoControl(hf, 4, @reg, sizeOf(reg), @reg, sizeOf(reg), pok, nil); isOK:=isOK and (not odd(reg.reg_Flags)); FloppySecRW:=isOK; end; function FloppyEnd(DriverNum:dword):Boolean; var reg:record reg_EBX:DWORD; reg_EDX:DWORD; reg_ECX:DWORD; reg_EAX:DWORD; reg_EDI:DWORD; reg_ESI:DWORD; reg_Flags:DWORD; end; pok:dword; isOK:Boolean; begin reg.reg_EAX:=$440D; reg.reg_EBX:=DriverNum; reg.reg_ECX:=$849; reg.reg_EDX:=0; reg.reg_EDI:=0; reg.reg_ESI:=0; reg.reg_Flags:=0; isOK:=DeviceIoControl(hf, 1, @reg, sizeOf(reg), @reg, sizeOf(reg), pok, nil); isOK:=isOK and (not odd(reg.reg_Flags)); FloppyEnd:=isOK; end; procedure Change9x(); var buf:array[1..512] of byte; ErrMSG:String; szDriver:String; Driver:dword; Serial:DWORD; diskType:integer; begin setLength(szDriver,9); GetWindowText(hID,PChar(szDriver),10); Delete(szDriver,5,1); Serial:=strtoint('$'+szDriver); setLength(szDriver,2); GetWindowText(hDrive,PChar(szDriver),3); diskType:=GetDriveType(PChar(szDriver+'\')); Driver:=ord(szDriver[1]); hf:=CreateFile('\\.\vwin32', 0, //GENERIC_READ or GENERIC_WRITE, 0, //FILE_SHARE_READ or FILE_SHARE_WRITE, nil, 0, //OPEN_EXISTING, $4000000, //FILE_ATTRIBUTE_NORMAL,//$4000000,//DELETE_ON_CLOSE 0); if hf<>$FFFFFFFF then begin case (diskType) of 2:begin //floppy Driver:=Driver-$40; if LockDisk(Driver,0,0) then begin if FloppySecRW(Driver,dword(@buf),2) then begin if FillSerial(dword(@buf),Serial)<4 then begin if FloppySecRW(Driver,dword(@buf),3) then begin FloppyEnd(Driver); UnLockDisk(Driver); ErrMSG:='恭喜!!修改序列号成功!'; end else ErrMSG:='错误!写磁盘错误!!'; end else ErrMSG:='错误!磁盘格式不支持!!'; end else ErrMSG:='错误!读磁盘错误!!'; end else ErrMSG:='错误!锁定磁盘失败!! '; end; 3:begin //hard Driver:=Driver-$40; if LockDisk(Driver,1,1) and LockDisk(Driver,2,0) then begin if ReadHardSec(Driver,dword(@buf)) then begin if FillSerial(dword(@buf),Serial)<4 then begin if WriteHardSec(Driver,dword(@buf)) then begin UnLockDisk(Driver); UnLockDisk(Driver); ErrMSG:='恭喜!!修改序列号成功!'; end else ErrMSG:='错误!写磁盘错误!!'; end else ErrMSG:='错误!磁盘格式不支持!!'; end else ErrMSG:='错误!读磁盘错误!!'; end else ErrMSG:='错误!锁定磁盘失败!! '; end else ErrMSG:='错误!不可操纵磁盘!!'; end; CloseHandle(hf); end else ErrMSG:='无法打开VWIN32服务!!'; MessageBox(hWindow,PChar(ErrMSG),PChar(copy(ErrMSG,1,6)),0); end; procedure ChangeNT(); var hf:THandle; buf:array[1..512] of byte; pok:dword; Driver:string; ErrMSG:string; Serial:DWORD; begin setLength(Driver,9); GetWindowText(hID,PChar(Driver),10); Delete(Driver,5,1); Serial:=strtoint('$'+Driver); //Serial:=$88888888; setLength(Driver,2); GetWindowText(hDrive,PChar(Driver),3); Driver:='\\.\'+Driver; hf:=CreateFile(PChar(Driver), GENERIC_READ or GENERIC_WRITE, FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0); if hf<>$FFFFFFFF then begin if ReadFile(hf,buf,512,pok,nil) then begin if FillSerial(dword(@buf),Serial)<>4 then begin SetFilePointer(hf,0,nil,0); if WriteFile(hf,buf,512,pok,nil) then begin if pok<>512 then ErrMSG:='错误!修改序列号不成功!' else ErrMSG:='恭喜!!修改序列号成功!';//写文件成功 end else begin ErrMSG:='错误!写磁盘共享错误!!' end; end else begin ErrMSG:='错误!磁盘格式不支持!!' end; end else begin ErrMSG:='错误!读磁盘共享错误!!' end; CloseHandle(hf); end else begin ErrMSG:='错误!打开磁盘共享错误!' end; MessageBox(hWindow,PChar(ErrMSG),PChar(copy(ErrMSG,1,6)),0); setLength(Driver,0); end; procedure getDrive(); var Device:Dword; D:integer; str:String; begin Device:=GetLogicalDrives; D:=$40; repeat inc(D); if odd(Device) then begin str:=char(D)+':'; SendMessage(hDrive, CB_ADDSTRING, 0, lParam(str) ); end; Device:=Device shr 1; until Device=0; SendMessage(hDrive,CB_SELECTSTRING,0,LParam(PChar('C:')) ); end; procedure initSerial(); var root:String; serial:dword; t1:dword; begin setLength(root,2); GetWindowText(hDrive,PChar(root),3); if not GetVolumeInformation(PChar(root+'\'),nil,0,@serial,t1,t1,nil,0) then begin serial:=0; MessageBox(hWindow,'获取序列号失败','提示',0); end; setLength(root,0); root:=toString(serial); SetWindowText(hID,PChar(root)); end; function WindowProc(hWindow: HWnd; Message,wParam,lParam: Integer): Integer; stdcall; procedure DrawBox(hdc,x1,y1,x2,y2:integer); begin MoveToEx(hdc,x1,y1,nil); LineTo(hdc,x1,y2); LineTo(hdc,x2,y2); LineTo(hdc,x2,y1); LineTo(hdc,x1,y1); end; begin Result := 0; { Checks for messages } case Message of WM_CREATE: begin InitCommonControls; end; WM_SHOWWindow:begin //getDrive; end; WM_COMMAND: begin if ((HWND(lParam) = hDrive))then begin if (wparam=$90000) then initSerial; end; if HWND(lParam) = cmbChange then if isNT then ChangeNT() else Change9x(); if HWND(lParam) = cmbAbout then MessageBox(hwindow,'Original CoDE bY DiKeN/iPB'#13#10#13#10'Latest Update bY heXer/iPB'#13#10#13#10'inside pandora''s Box'#13#10#13#10'http://www.ipbchina.org','磁盘序列号修改器 for WinALL',0); if HWND(lParam) = cmbExit then SendMessage(hWindow,WM_DESTROY,0,0); end; WM_PAINT:begin PaintDC := BeginPaint(hWindow,PaintStruct); DrawBox(PaintDC,5,5,163,78); DrawBox(PaintDC,7,59,161,76); hFont1 := CreateFont(-11,0,0,0,FW_BOLD,0,0,0,DEFAULT_CHARSET,0,0,0,0,'MS Sans Serif'); SelectObject(PaintDC,hFont1); SetBkColor(PaintDC,GetSysColor(COLOR_BTNFACE)); SetTextColor(PaintDC,RGB($33,$99,$33)); TextOut(PaintDC,25,60,'inside Pandora''s Box',20); SelectObject(PaintDC,hFont1); end; WM_DESTROY: begin DeleteObject(hFont1); PostQuitMessage(0); Exit; end; else Result := DefWindowProc(hWindow, Message, wParam, lParam); end; end; begin Inst := hInstance; with WinClass do begin style := CS_CLASSDC or CS_PARENTDC; lpfnWndProc := @WindowProc; hInstance := Inst; hbrBackground := color_btnface +1; lpszClassname := 'HID'; hIcon := 0;// hCursor := LoadCursor(0,IDC_ARROW); end; { with } WinClass.hIcon:=LoadIcon(Inst,'MAINICON'); RegisterClass(WinClass); //'MS Sans Serif' hFont1:=CreateFont(-11,0,0,0,0,0,0,0,DEFAULT_CHARSET,0,0,0,0,'MS Sans Serif'); SelectObject(PaintDC,hFont1); //Create Main Window ========= hWindow := CreateWindowEx(WS_EX_WINDOWEDGE, 'HID', '序列号修改器', WS_VISIBLE or WS_MINIMIZEBOX or WS_SYSMENU, 193,150,175,140,0, 0, Inst, nil); htitle:=Createwindow('STATIC', '驱动器:', WS_VISIBLE or WS_CHILD or SS_LEFT, 12,10,50,15, hWindow, 0, Inst, nil); SendMessage(htitle,WM_SETFONT,hFont1,0); hDrive:= CreateWindow('COMBOBOX','C:\',WS_VISIBLE or WS_CHILD or CBS_DROPDOWNLIST or WS_TABSTOP, 12,26,42,126, hWindow, 0, Inst, nil); getDrive; htitle:=Createwindow('STATIC', '序列号:', WS_VISIBLE or WS_CHILD or SS_LEFT, 62,10,50,15, hWindow, 0, Inst, nil); SendMessage(htitle,WM_SETFONT,hFont1,0); hID:= CreateWindowEx(WS_EX_CLIENTEDGE, 'EDIT', '1979-1126', WS_CHILD or WS_VISIBLE or WS_TABSTOP or ES_AUTOHSCROLL or WS_EX_STATICEDGE or WS_BORDER, 60,26,95,23, hWindow, 0, Inst, nil); SendMessage(hID,EM_LIMITTEXT,LParam(9),WParam(9)); initSerial; cmbChange := CreateWindow( 'BUTTON','改变',WS_VISIBLE or WS_CHILD or BS_PUSHLIKE or BS_TEXT or WS_TABSTOP or BS_FLAT, 5,85,50,22, hWindow, 0, Inst, nil); cmbAbout:= CreateWindow( 'BUTTON','关于',WS_EX_STATICEDGE or WS_VISIBLE or WS_CHILD or BS_PUSHLIKE or BS_TEXT or WS_TABSTOP or BS_FLAT , 60,85,50,22, hWindow, 0, Inst, nil); cmbExit:= CreateWindow( 'BUTTON','退出',WS_VISIBLE or WS_CHILD or BS_PUSHLIKE or BS_TEXT or WS_TABSTOP or BS_Flat, 115,85,50,22, hWindow, 0, Inst, nil); isNT:=false; if GetVersion shr 31=0 then isNT:=true; SendMessage(cmbChange,WM_SETFONT,hFont1,0); SendMessage(cmbAbout,WM_SETFONT,hFont1,0); SendMessage(cmbExit,WM_SETFONT,hFont1,0); while GetMessage(TheMessage,0,0,0) do begin if not IsDialogMessage(hWindow,TheMessage) then begin TranslateMessage(TheMessage); DispatchMessage(TheMessage); end; end; end. |
原创文章,转载请注明: 转载自火星信息安全研究院
本文链接地址: Delphi Get HDD Serial Number: http://www.h4ck.org.cn/2011/09/delphi-get-hdd-serial-number/