42 lines
1.2 KiB
Plaintext
42 lines
1.2 KiB
Plaintext
/*
|
|
文件名:MD5Class.nut
|
|
路径:Dps_A/BaseClass/MD5Class/MD5Class.nut
|
|
创建日期:2024-09-20 00:06
|
|
文件用途:MD5类
|
|
*/
|
|
class MD5 {
|
|
MD5_Init_ptr = Module.getExportByName(null, "MD5_Init");
|
|
MD5_Update_ptr = Module.getExportByName(null, "MD5_Update");
|
|
MD5_Final_ptr = Module.getExportByName(null, "MD5_Final");
|
|
|
|
function MD5_Init(Ctx) {
|
|
Sq_CallFunc(MD5_Init_ptr, "void", ["pointer"], Ctx);
|
|
}
|
|
|
|
function MD5_Update(Ctx, Buffer, Size) {
|
|
Sq_CallFunc(MD5_Update_ptr, "void", ["pointer", "pointer", "int"], Ctx, Buffer, Size);
|
|
}
|
|
|
|
function MD5_Final(Ctx, Result) {
|
|
Sq_CallFunc(MD5_Final_ptr, "void", ["pointer", "pointer"], Ctx, Result);
|
|
}
|
|
|
|
function GetFile(FileName) {
|
|
local Io = IO(FileName, "r+");
|
|
|
|
local Ctx = Memory.alloc(0x100);
|
|
MD5.MD5_Init(Ctx.C_Object);
|
|
|
|
while (true) {
|
|
local Buffer = Memory.alloc(0x1000);
|
|
local Res = Io.ReadBuffer(0x1000);
|
|
if (Res.count == 0) break;
|
|
MD5.MD5_Update(Ctx.C_Object, Memory.allocUtf8String(Res.str).C_Object, Res.count);
|
|
}
|
|
|
|
local Result = Memory.alloc(16);
|
|
MD5.MD5_Final(Result.C_Object, Ctx.C_Object);
|
|
Io.Close();
|
|
return Result.readUtf8String(16);
|
|
}
|
|
} |