本帖最后由 冥界3大法王 于 2021-10-15 17:47 编辑
用x64dbg调试跟踪了一个程序,发现在把注册表键值转换的过程中使用了HexToStr函数
注册表键值是:0044ADA2C8E8FCEDCBB5CBC2441556C67A1E40FA562A6BBC2C6211DCB0B711A02572506AB0CCBADDE3437CDCFBFA9AEFFCB7F949D1F8E0FEDC806EF6B7756689840D6B20C0D8AB9733BDD87B07DCE2E73B5CBCF3FBDD0A4EB7A9C1349D971C72EF603A93B8664CB17E39F0ED588E5F949F7AC4BDB0591954EB41A4EFA5D74549
转换后得到的字符串为:S159991189098765
以下是我从网上找的转换函数,随便编的一个转换程序,得到的执行结果是:
.D..........D.V.z.@.V*k.,b......%rPj.....C|........I......n..uf...k ....3..{....;\.....N...4...r.`:..fL.~9..X._..z...Y.T.A....EI
所以,问题来,如何才能得到转换后的字符串为粉色字符串?
[Delphi] 纯文本查看 复制代码 unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
Vcl.StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
Edit2: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function TransChar(AChar: Char): Integer;
begin
if AChar in ['0'..'9'] then
Result := Ord(AChar) - Ord('0')
else
Result := 10 + Ord(AChar) - Ord('A');
end;
function StrToHex(AStr: string): string;
var
I, Len: Integer;
s: char;
begin
Len := length(AStr);
Result := '';
for I := 1 to Len do
begin
s := AStr[I];
Result := Result + ' ' + IntToHex(Ord(s), 2); //将字符串转化为16进制字符串,
//并以空格间隔。
end;
Delete(Result, 1, 1); //删去字符串中第一个空格
end;
function HexToStr(AStr: string): string;
var
I, len: Integer;
CharValue: Word;
Tmp: string;
s: char;
begin
Tmp := '';
len := length(AStr);
for I := 1 to len do
begin
s := AStr[I];
if s <> ' ' then
Tmp := Tmp + string(s);
end;
Result := '';
for I := 1 to Trunc(Length(Tmp) / 2) do
begin
Result := Result + ' ';
CharValue := TransChar(Tmp[2 * I - 1]) * 16 + TransChar(Tmp[2 * I]);
if (CharValue < 32) or (CharValue > 126) then
Result[I] := '.' //非可见字符填充
else
Result[I] := Char(CharValue);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Edit2.Text := HexToStr(Edit1.Text);
end;
end.
是发生反应的物质有问题? 还是漏掉了什么关键情节? |