帮忙转换两段Delphi代码(转换成C#的),重谢

zhanglizhao zhanglizhao 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
没接触过Delphi,希望学过的兄弟帮个忙,万分感谢!!


const
titlestr:array[0..15] of byte=
($00,$01,$00,$00,$53,$74,$61,$6E,$64,$61,$72,$64,$20,$4A,$65,$74) ;//对应MDB文件的前16个字节
titlestr2:array[0..15] of byte=
($48,$4A,$00,$58,$55,$43,$48,$41,$4E,$47,$59,$4F,$55,$00,$20,$20) ;//更改后的MDB文件的前16个字节,自己随便写吧,比如写上自己公司的简称或自已的名
produce EncrypMDB(filename:string); //用titlestr2内容替换MDB前16个字节,以便实现加密的作用
var F:TFileStream;
begin
if not fileExists(filename) then exit;
F:=TFileStream.create(filename,fmopenwrite);
try
F.seek($00,soFromBeginning);
F.Write(titlestr2,16);
finally
F.free;
end;
end;
produce uncrypMDB(filename:string); //还原MDB前16个字节
var F:TFileStream;
begin
if not fileExists(filename) then exit;
F:=TFileStream.create(filename,fmopenwrite);
try
F.seek($00,soFromBeginning);
F.Write(titlestr,16);
finally
F.free;
end;
end;

uncrypMDB(App_path+'data\temp.db');
copyfile(pchar(App_path+'data\temp.db'),pchar(APP_path+'\data\account.db'),false);
adoconn.connectionstring:='provider=Microsoft.Jet.OLEDB.4.0;Data Source='+App_path+'data\account.db;Persist Security Info=false'; //adocon是个TADOConnection组件
try
adoconn.connected:=true;
except
MessageBox(handle,'打开数据库出现致命的错误!!!','错误',MB_OK+MB_ICONERROR);
end;
//打开后马上对其加密
copyfile(pchar(APP_path+'\data\account.db'),pchar(app_path+'data\temp.db'),false); //app_path表示程序的当前目录,account.db是个更改了扩展名的MDB文件
EncrypMDB(App_path+'data\temp.db');
copyfile(pchar(App_path+'data\temp.db'),pchar(APP_path+'\data\account.db'),false);
deletefile(App_path+'data\temp.db');

reg:=TRegistry.Create;
try
reg.RootKey:=HKEY_CLASSES_ROOT;
reg.OpenKey('.ldb');
reg.WriteString(','tempfile');
finally
reg.closekey;
reg.free;
end;
...全文
评论 6
收藏 已收藏
分享
返回顶部
zhanglizhao
C# 111,129 成员 642,539 内容