Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- format PE console 4.0
- include 'win32a.inc'
- jmp a0
- data import
- ;krnlname:
- library kernel32,'KERNEL32.DLL'
- import kernel32,\
- CloseHandle,'CloseHandle',\
- CreateFile,'CreateFileA',\
- FreeEnvironmentStrings,'FreeEnvironmentStringsA',\
- FreeLibrary,'FreeLibrary',\
- GetCurrentProcessId,'GetCurrentProcessId',\
- GetCurrentThreadId,'GetCurrentThreadId',\
- GetDiskFreeSpaceEx,'GetDiskFreeSpaceExA',\
- GetEnvironmentStrings,'GetEnvironmentStringsA',\
- GetProcAddress,'GetProcAddress',\
- GetStdHandle,'GetStdHandle',\
- GetSystemTime,'GetSystemTime',\
- GetSystemTimeAsFileTime,'GetSystemTimeAsFileTime',\
- GetTickCount,'GetTickCount',\
- GlobalMemoryStatus,'GlobalMemoryStatus',\
- LoadLibrary,'LoadLibraryA',\
- ReadFile,'ReadFile',\
- VirtualAlloc,'VirtualAlloc',\
- VirtualFree,'VirtualFree',\
- WriteFile,'WriteFile',\
- ExitProcess,'ExitProcess'
- end data
- RandSeed db 20 dup 0
- Rand_SysData db 64 dup 0
- Rand_Context db 104 dup 0
- ARC_Context db 258 dup 0
- Rand_KRNL db 'KERNEL32.DLL',0
- ;krnladdr dd krnlname
- Rand_GMSE db 'GlobalMemoryStatusEx',0
- Rand_HMOD dd 0
- stdout dd 0
- bittable dd 0
- tmptable dd 0
- blocksize dw 4 ; VERY IMPORTANT - must be divisable by 4
- sblocksize dd 0
- powermod db $01,$AB,$CD,$B7,$39,$A3,$C5,$EF,$F1,$1B,$3D,$A7,$29,$13,$35,$DF ;PowerMod[i*2+1,-1,256]
- db $E1,$8B,$AD,$97,$19,$83,$A5,$CF,$D1,$FB,$1D,$87,$09,$F3,$15,$BF ; i.e. if we want to calculate PowerMod[x,-1,256] where x is odd number between 1 and 255,
- db $C1,$6B,$8D,$77,$F9,$63,$85,$AF,$B1,$DB,$FD,$67,$E9,$D3,$F5,$9F ; shr eax,1
- db $A1,$4B,$6D,$57,$D9,$43,$65,$8F,$91,$BB,$DD,$47,$C9,$B3,$D5,$7F ; mov eax,[powermod+eax]
- db $81,$2B,$4D,$37,$B9,$23,$45,$6F,$71,$9B,$BD,$27,$A9,$93,$B5,$5F
- db $61,$0B,$2D,$17,$99,$03,$25,$4F,$51,$7B,$9D,$07,$89,$73,$95,$3F
- db $41,$EB,$0D,$F7,$79,$E3,$05,$2F,$31,$5B,$7D,$E7,$69,$53,$75,$1F
- db $21,$CB,$ED,$D7,$59,$C3,$E5,$0F,$11,$3B,$5D,$C7,$49,$33,$55,$FF
- memerr db 'Memory allocation error',13,10
- memerrl = $-memerr
- forwardname db 'forward.bin',0
- backwardname db 'backward.bin',0
- ;here subs
- noconst = 1
- include 'sha1.inc'
- include 'ISCrypt.inc'
- a0:
- mov ax,[blocksize]
- mul ax
- xchg dx,ax
- shl eax,16
- mov ax,dx
- mov [sblocksize],eax
- stdcall SHA1Reset,Rand_Context
- invoke GetCurrentProcessId
- mov dword[Rand_SysData],eax
- stdcall SHA1Input,Rand_Context,Rand_SysData,4
- invoke GetCurrentThreadId
- mov dword[Rand_SysData],eax
- stdcall SHA1Input,Rand_Context,Rand_SysData,4
- invoke GetDiskFreeSpaceEx,0,Rand_SysData,Rand_SysData+8,Rand_SysData+16
- stdcall SHA1Input,Rand_Context,Rand_SysData,24
- invoke GetEnvironmentStrings
- mov dword[Rand_SysData],eax
- Rand_for1begin:
- cmp byte[eax],0
- jz Rand_for1end
- @@:
- cmp byte[eax],0
- jz @f
- inc eax
- jmp @b
- @@:
- inc eax
- jmp Rand_for1begin
- Rand_for1end:
- sub eax,dword[Rand_SysData]
- stdcall SHA1Input,Rand_Context,dword[Rand_SysData],eax
- invoke FreeEnvironmentStrings,dword[Rand_SysData]
- invoke GetSystemTime,Rand_SysData
- stdcall SHA1Input,Rand_Context,Rand_SysData,16
- invoke GetSystemTimeAsFileTime,Rand_SysData
- stdcall SHA1Input,Rand_Context,Rand_SysData,8
- invoke GetTickCount
- mov dword[Rand_SysData],eax
- stdcall SHA1Input,Rand_Context,Rand_SysData,4
- invoke LoadLibrary,Rand_KRNL
- ;invoke LoadLibrary,krnlname+$28
- or eax,eax
- jz Rand_nolib
- mov [Rand_HMOD],eax
- invoke GetProcAddress,[Rand_HMOD],Rand_GMSE
- or eax,eax
- jz Rand_noproc
- mov dword[Rand_SysData],64
- stdcall eax,Rand_SysData
- stdcall SHA1Input,Rand_Context,Rand_SysData,64
- jmp @f
- Rand_noproc:
- invoke FreeLibrary,[Rand_HMOD]
- Rand_nolib:
- mov dword[Rand_SysData],32
- invoke GlobalMemoryStatus,Rand_SysData
- stdcall SHA1Input,Rand_Context,Rand_SysData,32
- @@:
- stdcall SHA1Result,Rand_Context,RandSeed
- stdcall ArcFourInit,ARC_Context,RandSeed,20
- stdcall ArcFourCrypt,ARC_Context,0,0,1000
- ; now RandSeed is initialised
- invoke GetStdHandle,$FFFFFFF5
- mov [stdout],eax
- invoke VirtualAlloc,0,[sblocksize],MEM_COMMIT,PAGE_READWRITE
- mov [bittable],eax
- or eax,eax
- jnz @f
- pmemerr:
- invoke WriteFile,[stdout],memerr,memerrl,RandSeed,0
- jmp exit
- @@:
- invoke VirtualAlloc,0,[sblocksize],MEM_COMMIT,PAGE_READWRITE
- mov [tmptable],eax
- or eax,eax
- jz pmemerr
- ; now memory is allocated
- cld
- mov ebp,[tmptable]
- movzx edx,[blocksize]
- mainloop: ;ok=ebx, n=edx, i=esi, j=edi,
- mov ecx,[sblocksize]
- stdcall ArcFourCrypt,ARC_Context,0,[bittable],ecx ;bittable = Table[RandomInteger[], {i, n}, {j, n}];
- ; now matrix is filled, check - it's det must be odd
- shr ecx,2
- mov esi,[bittable]
- mov edi,ebp
- rep movsd ;tmptable = bittable;
- xor ebx,ebx
- inc ebx ;ok = True;
- xor esi,esi ;i = 1; because 0..n-1
- lab2:
- lea eax,[edx-1] ; because 0..n-1
- cmp esi,eax
- je lab3 ;If[i == n, Goto[lab3]];
- mov ecx,edx
- mov eax,esi
- mul cx
- xchg dx,ax
- shl eax,16
- mov ax,dx
- mov edx,ecx
- add eax,ebp
- mov al,byte[eax+esi]
- bt eax,0
- jc lab4 ;If[tmptable[[i, i]] != 0, Goto[lab4]];
- xor ebx,ebx ;ok = False;
- mov edi,esi
- inc edi ;j = i + 1;
- lab6:
- cmp edi,edx
- je lab5 ;If[j > n, Goto[lab5]];
- mov ecx,edx
- mov eax,edi
- mul cx
- xchg dx,ax
- shl eax,16
- mov ax,dx
- mov edx,ecx
- add eax,ebp
- mov al,byte[eax+esi]
- bt eax,0
- jnc lab7 ;If[tmptable[[j, i]] != 1, Goto[lab7]];
- push esi
- push edi
- mov ecx,edx
- mov eax,esi
- mul cx
- xchg dx,ax
- shl eax,16
- mov ax,dx
- mov esi,eax ;now esi=i*n
- mov eax,edi
- mul cx
- xchg dx,ax
- shl eax,16
- mov ax,dx
- mov edi,eax ;now edi=j*n
- mov edx,ecx
- shr edx,2
- xor ecx,ecx
- @@:
- xchg eax,[ebp+esi]
- xchg eax,[ebp+edi]
- xchg eax,[ebp+esi]
- inc ecx
- add ebp,4
- cmp ecx,edx
- jne @b
- mov ebp,[tmptable]
- movzx edx,[blocksize]
- pop edi
- pop esi ;tmpline = tmptable[[i]];tmptable[[i]] = tmptable[[j]];tmptable[[j]] = tmpline;
- xor ebx,ebx
- inc ebx ;ok = True;
- jmp lab5
- lab7:
- inc edi ;j++;
- jmp lab6
- lab5:
- or ebx,ebx
- jz lab3 ;If[! ok, Goto[lab3]];
- lab4:
- mov edi,esi
- inc edi ;j = i + 1;
- lab8:
- cmp edi,edx
- je lab9 ;If[j > n, Goto[lab9]];
- mov ecx,edx
- mov eax,edi
- mul cx
- xchg dx,ax
- shl eax,16
- mov ax,dx
- mov edx,ecx
- add eax,ebp
- mov al,byte[eax+esi]
- bt eax,0
- jnc lab10 ;If[tmptable[[j, i]] != 1, Goto[lab10]];
- push esi
- push edi
- mov ecx,edx
- mov eax,esi
- mul cx
- xchg dx,ax
- shl eax,16
- mov ax,dx
- mov esi,eax ;now esi=i*n
- mov eax,edi
- mul cx
- xchg dx,ax
- shl eax,16
- mov ax,dx
- mov edi,eax ;now edi=j*n
- mov edx,ecx
- shr edx,2
- xor ecx,ecx
- @@:
- mov eax,[edi+ebp]
- xor eax,[esi+ebp]
- mov [edi+ebp],eax
- inc ecx
- add ebp,4
- cmp ecx,edx
- jne @b
- mov ebp,[tmptable]
- movzx edx,[blocksize]
- pop edi
- pop esi ;tmptable[[j]] = BitXor[tmptable[[i]], tmptable[[j]]];
- lab10:
- inc edi ;j++;
- jmp lab8
- lab9:
- inc esi ;i++;
- jmp lab2
- lab3:
- or ebx,ebx
- jz mainloop ;If[! ok, Goto[lab1]];
- mov eax,[sblocksize]
- dec eax
- movzx eax,byte[ebp+eax]
- bt eax,0
- jnc mainloop
- ;now we must check bittable for zeros and if there any, change them to random even number
- mov esi,[bittable]
- xor ecx,ecx
- mov edx,[sblocksize]
- dezero_loop:
- movzx eax,byte[esi]
- or eax,eax
- jnz @f
- stdcall ArcFourCrypt,ARC_Context,eax,esi,1
- and byte[esi],$FE
- jmp dezero_loop
- @@:
- inc esi
- inc ecx
- cmp ecx,edx
- jnz dezero_loop
- invoke CreateFile,forwardname,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL
- mov [Rand_HMOD],eax
- invoke WriteFile,eax,[bittable],[sblocksize],RandSeed,NULL
- invoke CloseHandle,[Rand_HMOD]
- ;calculate inverse matrix
- ;bittable contains keytable, there will be identity matrix
- ;tmptable will contain inverse matrix
- mov ecx,[sblocksize]
- xor eax,eax
- mov edi,[tmptable]
- rep stosd
- invoke CreateFile,backwardname,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL
- mov [Rand_HMOD],eax
- invoke WriteFile,eax,[tmptable],[sblocksize],RandSeed,NULL
- invoke CloseHandle,[Rand_HMOD]
- exit: invoke ExitProcess,0
Add Comment
Please, Sign In to add comment