Last active
June 6, 2016 02:43
-
-
Save dumpmycode/a5d14d113c9424f1e252c51788f50af6 to your computer and use it in GitHub Desktop.
CDKey.asm - skullsecurity.org
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| segment .data | |
| cdkey db "1111111111111" | |
| segment .text | |
| global _start | |
| _start: | |
| mov ecx, cdkey | |
| mov eax, 3 ; eax = 3 | |
| mov esi, ecx ; esi = ecx, ecx = 13 digit starcraft cd key entered | |
| xor ecx, ecx ; ecx = 0 | |
| Top: | |
| movsx edx, byte [ecx+esi] ; move sign extension retains sign flag of 1 byte at address [ecx+esi] to edx. | |
| sub edx, 30h ; convert ascii char in form of hex to actual integer number. "0" is 0x30 - 0x30 = 0 integer | |
| lea edi, [eax+eax] ; load effective address allows complex calculation e.g. [eax*ebx+5] faster than add/mul | |
| ; and can store result in register other than source register e.g. (eax in case of mul) | |
| ; LEA instruction calculates [eax+eax] or more like [eax]+[eax] operation and store value | |
| ; result in edi = 6 whereas; | |
| ; MOV will calculate [eax+eax] which is [6] and tries to look for value in memory address 0x00000006 | |
| ; to store in edi, end up as invalid address and crash. | |
| xor edx, edi ; xor byteswap calculation and store result in edx | |
| add eax, edx ; accumulate xor result to eax | |
| inc ecx ; increment counter ecx | |
| cmp ecx, 0Ch ; once 12 digits processed, move to next intructions. | |
| ; not sure why it doesnt process all 13 digits. | |
| jl short Top ; otherwise, go back to Top: | |
| xor edx, edx ; clear out edx in preparation of div instruction which may have remainder | |
| ; and will be put in edx if there is a remainder. | |
| mov ecx, 0Ah ; move 10 to ecx, act as divisor. | |
| div ecx ; divide eax / ecx, quotient stored in eax, remainder stored in edx | |
| movsx eax, byte [esi+0Ch] ; move last digit value to eax. cdkey[-1] | |
| add edx, 30h ; convert int value(1) back to ascii value(0x31) | |
| cmp eax, edx ; compare if 13th digit == remainder, if true we exit with 1 in eax | |
| jnz bottom ; if not true, exit to bottom with 0 in eax: | |
| mov eax, 1 | |
| ret | |
| bottom: | |
| xor eax, eax | |
| ret | |
| I tried to interpret it in python: | |
| #! /usr/bin/env python | |
| import subprocess as sub | |
| sub.Popen('clear').communicate()[0] | |
| cdkey = raw_input('enter cd key: ') | |
| eax, ecx, edx = 3, 0, 0 | |
| with open('cdkey.txt','w+') as fobj: | |
| for i in cdkey[:-1]: | |
| eax += int(i) ^ (eax+eax) | |
| ecx += 1 | |
| fobj.write('eax = {}\necx = {}\n\n'.format(hex(eax),ecx)) | |
| if (cdkey[-1]) == str(eax%10): | |
| print('CDKey is valid.') | |
| else: | |
| print('CDKey not valid.') | |
| print 'eax = ',hex(eax) | |
| print 'remainder = ', eax%10 | |
| print 'last digit of cdkey = ', cdkey[-1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment