直接看算法
因为比较简单所以我们直接看F5后的伪代码
void __fastcall __noreturn main(__int64 a1, char **a2, char **a3)
{
size_t v3; // rsi
int i; // [rsp+3Ch] [rbp-54h]
char s[36]; // [rsp+40h] [rbp-50h]
int v6; // [rsp+64h] [rbp-2Ch]
__int64 v7; // [rsp+68h] [rbp-28h]
char v8[8]; // [rsp+70h] [rbp-20h]
int v9; // [rsp+8Ch] [rbp-4h]
v9 = 0;
strcpy(v8, ":\"AL_RT^L*.?+6/46");
v7 = 28537194573619560LL;
v6 = 7;
printf("Welcome to the RC3 secure password guesser.\n", a2, a3);
printf("To continue, you must enter the correct password.\n");
printf("Enter your guess: ");
__isoc99_scanf("%32s", s);//输入字符串
v3 = strlen(s);
if ( v3 < strlen(v8) )
sub_4007C0();
for ( i = 0; i < strlen(s); ++i )
{
if ( i >= strlen(v8) )
sub_4007C0();
if ( s[i] != (char)(*((_BYTE *)&v7 + i % v6) ^ v8[i]) )
sub_4007C0();
}
sub_4007F0();
}
代码的逻辑很简单,就是输入一个字符串s
,然后检查长度是否为固定长,第一个判断不能小,第二个判断不能大,所以就是相等咯。最后判断字符串是否与给定的字符串相等。解出给定的字符串就可以了。
注意
1.strcpy
这个函数,虽然char v8[8]
,但是strcpy
不管这些,是多少就复制多少过去。
2.就是写代码的时候,注意初始化char s[36]
,因为for循环
里面有一个strlen
函数,官方文档里面有这么一句话:
The length of a C string is determined by the terminating null-character: A C string is as long as the number of characters between the beginning of the string and the terminating null character (without including the terminating null character itself).
This should not be confused with the size of the array that holds the
string.
所以char s[18]="aaaaaaassaaaaaaaa";
这里长度18是因为字符串最后一位留0
,而v8
的长度为17,不是很清楚这种做法是否为最优的做法。
代码
#include <iostream>
#include <Windows.h>
using namespace std;
int main()
{
int i; // [rsp+3Ch] [rbp-54h]
char s[18]="aaaaaaassaaaaaaaa"; // [rsp+40h] [rbp-50h]
int v6; // [rsp+64h] [rbp-2Ch]
__int64 v7; // [rsp+68h] [rbp-28h]
char v8[17]; // [rsp+70h] [rbp-20h]
strcpy(v8, ":\"AL_RT^L*.?+6/46");
v7 = 28537194573619560LL;
v6 = 7;
for ( i = 0; i < strlen(s); ++i )
{
s[i] = (char)(*((BYTE *)&v7 + i % v6) ^ v8[i]);
}
cout<<s;
system("pause");
return 0;
}
FLAG RC3-2016-XORISGUD