Created
December 16, 2012 19:03
-
-
Save shouya/4311384 to your computer and use it in GitHub Desktop.
Disassembly-ing LockPwd function!
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
int __stdcall LockPwd(char *a1, char *a2) | |
{ | |
signed int lcs2; // esi@1 | |
signed int lcs1; // edi@1 | |
signed int j; // esi@7 | |
signed int k; // esi@15 | |
signed int l; // esi@22 | |
CString *cs1; // [sp+8h] [bp-Ch]@1 | |
CString *cs2; // [sp+Ch] [bp-8h]@1 | |
CString *cs3; // [sp+10h] [bp-4h]@1 | |
unsigned long *wtf; | |
cs3 = new CString; | |
cs2 = new CString(a1); | |
cs1 = new CString(a2); | |
lcs2 = cs2.length(); | |
cs2.SetAt(0, cs2.Length() - 1); | |
lcs1 = cs1.length(); | |
if ( lcs1 <= lcs2 ) | |
{ | |
cs2.Left(cs1.length()); | |
delete cs1; | |
} | |
else | |
{ | |
tmp = cs2; | |
for ( i = 0; cs2.length < lcs1; tmp = cs2 ) | |
{ | |
cs2 += tmp[i] | |
++i; | |
} | |
} | |
if ( *(_BYTE *)cs2 & 1 ) | |
{ | |
for ( j = 0; j < lcs1; ++j ) | |
{ | |
a1[j] = cs1[j]; | |
if (j % 2 == 1 && cs1[j] != '9') { | |
a1[j] = 'h' - cs1[j] | |
} | |
if ( j % 2 == 0 ) | |
a1[j] = 'i' - cs1[j]; | |
cs1.SetAt(j, a1[j]); | |
} | |
} | |
else | |
{ | |
for ( j = 0; j < lcs1; ++j ) | |
{ | |
a1 = cs1[j]; | |
if ( k % 2 == 0 && cs1[j] != '9' ) | |
{ | |
a1[j] = 'h' - cs1[j]; | |
} | |
if ( k % 2 == 1 ) | |
a1[j] = 'i' - cs1[j]; | |
cs1.SetAt(k, a1); | |
} | |
} | |
for ( l = 0; l < lcs1; ++l ) | |
{ | |
a1[l] = (cs2[l] ^ cs1[l]) + '0'; | |
if ( a1[l] <= '9' ) | |
cs1.setAt(l, a1[l]); | |
} | |
cs1 = cs1.MakeReverse; | |
return cs1; | |
} |
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
# a1 a2 | |
def lock_pwd(cardno, passwd) | |
cs3 = String.new | |
cs2 = cardno.dup | |
cs1 = passwd.dup | |
lcs2 = cs2.length | |
cs2[0] = lcs2.chr | |
lcs1 = cs1.length | |
if lcs1 <= lcs2 | |
cs2 = cs2[0, lcs1] | |
else | |
tmp = cs2.dup | |
i = 0 | |
while cs2.length < lcs1 | |
cs2 += tmp[i] | |
i += 1 | |
end | |
end | |
if false # WTF? | |
(0...lcs1).each do |j| | |
cardno[j] = cs1[j] | |
if j.odd? and cs1[j] != '9' | |
cardno[j] = ('h'.ord - cs1[j].ord).chr | |
end | |
if j.even? | |
cardno[j] = ('i'.ord - cs1[j].ord).chr | |
end | |
cs1[j] = cardno[j] | |
end | |
else | |
(0...lcs1).each do |j| | |
cardno[j] = cs1[j] | |
if j.even? and cs1[j] != '9' | |
cardno[j] = ('h'.ord - cs1[j].ord).chr | |
end | |
if j.odd? | |
cardno[j] = ('i'.ord - cs1[j].ord).chr | |
end | |
cs1[j] = cardno[j] | |
end | |
end | |
(0...lcs1).each do |l| | |
cardno[l] = ((cs2[l].ord ^ cs1[l].ord) + '0'.ord ).chr | |
if cardno[l] <= '9' | |
cs1[l] = cardno[l] | |
end | |
end | |
return cs1.reverse | |
end |
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
# a1 a2 | |
def unlock_pwd(barno, passwd) | |
cs1 = barno.dup | |
cs2 = passwd.dup | |
lcs1 = cs1.length | |
cs1[0] = cs1[-1] | |
lcs2 = cs2.length | |
if lcs2 <= lcs1 | |
cs1 = cs1[0, lcs2] | |
else | |
tmp = cs1.dup | |
i = 0 | |
while cs1.length < lcs2 | |
cs1 += tmp[i] | |
i += 1 | |
tmp = cs1.dup | |
end | |
end | |
cs2.reverse! | |
(0...lcs2).each do |j| | |
barno[j] = ((cs1[j].ord ^ cs2[j].ord) + 48).chr | |
cs2[j] = barno[j] if barno[j] <= '9' | |
end | |
if false # WTF? *(_BYTE *)cs1 & 1 | |
0.upto(lcs2 - 1) do |k| | |
tmp = cs2[k] | |
a1[k] = tmp | |
if k % 2 == 1 && tmp != '9' | |
tmp = ('h'.ord - tmp.ord).chr | |
a1[k] = tmp | |
end | |
if k % 2 == 0 | |
a1[k] = ('i'.ord - tmp.ord).chr | |
end | |
cs2[k] = a1[k] | |
end | |
else | |
0.upto(lcs2 - 1) do |k| | |
tmp = cs2[k] | |
barno[k] = tmp | |
if k % 2 == 0 && tmp != '9' | |
tmp = ('h'.ord - tmp.ord).chr | |
barno[k] = tmp | |
end | |
if k % 2 == 1 | |
barno[k] = ('i'.ord - tmp.ord).chr | |
end | |
cs2[k] = barno[k] | |
end | |
end | |
return cs2 | |
end | |
p unlock_pwd('0113912', '092102') |
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
int __stdcall UnLockPwd(int a1, int a2) | |
{ | |
signed int v2; // esi@1 | |
int v3; // edx@1 | |
int v4; // ecx@1 | |
signed int v5; // edi@1 | |
int v6; // eax@2 | |
int i; // esi@2 | |
signed int j; // esi@6 | |
signed int k; // esi@11 | |
char v10; // cl@12 | |
signed int l; // esi@19 | |
char v12; // cl@20 | |
int v13; // esi@26 | |
int cs2; // [sp+8h] [bp-Ch]@1 | |
int cs1; // [sp+Ch] [bp-8h]@1 | |
int v17; // [sp+10h] [bp-4h]@1 | |
CString::CString(&v17); | |
CString::CString(&cs1, a1); | |
CString::CString(&cs2, a2); | |
lcs1 = *(_DWORD *)(cs1 - 8); | |
LOBYTE(v3) = *(_BYTE *)(lcs1 + cs1 - 1); | |
CString::SetAt(&cs1, 0, v3); | |
lcs2 = *(_DWORD *)(cs2 - 8); | |
if ( lcs2 <= lcs1 ) | |
{ | |
CString::Left(&cs1, &a1, *(_DWORD *)(cs2 - 8)); | |
CString::_CString(&a1); | |
} | |
else | |
{ | |
v6 = cs1; | |
for ( i = 0; *(_DWORD *)(cs1 - 8) < lcs2; v6 = cs1 ) | |
{ | |
LOBYTE(v4) = *(_BYTE *)(i + v6); | |
CString::operator__(&cs1, v4); | |
++i; | |
} | |
} | |
CString::MakeReverse(&cs2); | |
for ( j = 0; j < lcs2; ++j ) | |
{ | |
LOBYTE(a1) = (*(_BYTE *)(j + cs1) ^ *(_BYTE *)(j + cs2)) + 48; | |
if ( (unsigned __int8)a1 <= 0x39u ) | |
CString::SetAt(&cs2, j, a1); | |
} | |
if ( *(_BYTE *)cs1 & 1 ) | |
{ | |
for ( k = 0; k < lcs2; ++k ) | |
{ | |
v10 = *(_BYTE *)(k + cs2); | |
LOBYTE(a1) = *(_BYTE *)(k + cs2); | |
if ( k % 2 == 1 && v10 != 57 ) | |
{ | |
v10 = 104 - v10; | |
LOBYTE(a1) = v10; | |
} | |
if ( !(k % 2) ) | |
LOBYTE(a1) = 105 - v10; | |
CString::SetAt(&cs2, k, a1); | |
} | |
} | |
else | |
{ | |
for ( l = 0; l < lcs2; ++l ) | |
{ | |
v12 = *(_BYTE *)(l + cs2); | |
LOBYTE(a1) = *(_BYTE *)(l + cs2); | |
if ( !(l % 2) && v12 != 57 ) | |
{ | |
v12 = 104 - v12; | |
LOBYTE(a1) = v12; | |
} | |
if ( l % 2 == 1 ) | |
LOBYTE(a1) = 105 - v12; | |
CString::SetAt(&cs2, l, a1); | |
} | |
} | |
CString::operator_(&v17, &cs2); | |
v13 = v17; | |
CString::_CString(&cs2); | |
CString::_CString(&cs1); | |
CString::_CString(&v17); | |
return v13; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment