使用 delphi 在 android 应用中使用序列号安全
using serial number security in android app using delphi
此代码在 Firemonkey Windows 应用程序中运行,但在 Android 应用程序中不起作用,我得到的是 Goodbye
而不是 Welcome
,出了什么问题?
Edit8 Text : 162496 //计算机唯一码
Edit9 文本:1564224593 //序列号#
procedure TForm2.Button5Click(Sender: TObject);
var
f2,f1:textfile;
i,j:byte;
s1,s2,s3,c:string;
F: TextFile;
begin
j:=0;
s2 := Edit8.Text;
for i:=1 to Length(s2) do
if (s2[i]>='0') and (s2[i]<='9') then
s3:=s3+s2[i];
for i:=1 to Length(s3)-1 do
if (edit9.Text[i*2-1]<>s3[i]) or (abs(strtoint(s3[i+1])-strtoint(s3[i]))<> strtoint(edit9.Text[i*2])) then
inc(j);
if j=0 then
ShowMessage('Welcome')
else
ShowMessage('Goodbye');
end;
Delphi 移动编译器使用 zero-based strings.
你有三个选择:
- 正如@Günter_the_Beautiful 指出的那样,您最好的选择是重写代码以使用 string helpers(始终基于 0)
- 重写代码以使用基于 0 的索引:
for I := 0 to ...
- 如果您需要快速修复,请使用
{$ZEROBASEDSTRINGS OFF}
指令在您的代码片段中将其关闭(并再次使用 {$ZEROBASEDSTRINGS ON}
恢复)。
对于选项 2. 和 3.,如果您需要跨平台的代码,请考虑使用合适的平台 conditional defines。这就是使选项 1 引人注目的原因:无需使用条件定义来混淆您的代码。
我正在使用这两个辅助例程:
FUNCTION GetChar(CONST S : STRING ; OneBasedIndex : LongWord) : CHAR;
BEGIN
{$IF CompilerVersion>=24 }
Result:=S[SUCC(OneBasedIndex-LOW(S))]
{$ELSE }
Result:=S[OneBasedIndex]
{$IFEND }
END;
PROCEDURE SetChar(VAR S : STRING ; OneBasedIndex : LongWord ; NewChar : CHAR);
BEGIN
{$IF CompilerVersion>=24 }
S[SUCC(OneBasedIndex-LOW(S))]:=NewChar
{$ELSE }
S[OneBasedIndex]:=NewChar
{$IFEND }
END;
这样,您可以继续使用基于 1 的字符串(这是合乎逻辑的选择:-)),只要您始终使用这两个函数将字符串作为字符访问即可。
此代码在 Firemonkey Windows 应用程序中运行,但在 Android 应用程序中不起作用,我得到的是 Goodbye
而不是 Welcome
,出了什么问题?
Edit8 Text : 162496 //计算机唯一码
Edit9 文本:1564224593 //序列号#
procedure TForm2.Button5Click(Sender: TObject);
var
f2,f1:textfile;
i,j:byte;
s1,s2,s3,c:string;
F: TextFile;
begin
j:=0;
s2 := Edit8.Text;
for i:=1 to Length(s2) do
if (s2[i]>='0') and (s2[i]<='9') then
s3:=s3+s2[i];
for i:=1 to Length(s3)-1 do
if (edit9.Text[i*2-1]<>s3[i]) or (abs(strtoint(s3[i+1])-strtoint(s3[i]))<> strtoint(edit9.Text[i*2])) then
inc(j);
if j=0 then
ShowMessage('Welcome')
else
ShowMessage('Goodbye');
end;
Delphi 移动编译器使用 zero-based strings.
你有三个选择:
- 正如@Günter_the_Beautiful 指出的那样,您最好的选择是重写代码以使用 string helpers(始终基于 0)
- 重写代码以使用基于 0 的索引:
for I := 0 to ...
- 如果您需要快速修复,请使用
{$ZEROBASEDSTRINGS OFF}
指令在您的代码片段中将其关闭(并再次使用{$ZEROBASEDSTRINGS ON}
恢复)。
对于选项 2. 和 3.,如果您需要跨平台的代码,请考虑使用合适的平台 conditional defines。这就是使选项 1 引人注目的原因:无需使用条件定义来混淆您的代码。
我正在使用这两个辅助例程:
FUNCTION GetChar(CONST S : STRING ; OneBasedIndex : LongWord) : CHAR;
BEGIN
{$IF CompilerVersion>=24 }
Result:=S[SUCC(OneBasedIndex-LOW(S))]
{$ELSE }
Result:=S[OneBasedIndex]
{$IFEND }
END;
PROCEDURE SetChar(VAR S : STRING ; OneBasedIndex : LongWord ; NewChar : CHAR);
BEGIN
{$IF CompilerVersion>=24 }
S[SUCC(OneBasedIndex-LOW(S))]:=NewChar
{$ELSE }
S[OneBasedIndex]:=NewChar
{$IFEND }
END;
这样,您可以继续使用基于 1 的字符串(这是合乎逻辑的选择:-)),只要您始终使用这两个函数将字符串作为字符访问即可。