事情是这样的
网友想调用dll,但是不想把dll释放到硬盘,想放在内存中。
俺的回答是:是从内存中,根据pe结构确定call的地址。
例子
先准备一个dll
library dll;
{$R *.res}
function getValue(p1, p2: integer): integer; stdcall
begin
result := p1 + p2;
end;
exports getValue;
begin
end.
这个dll 就是一个函数 getValue
把dll处理成字节流
其实这里最简单的方法是用res资源文件,调用的时候用,这样最简单。例如:
resStream := TResourceStream.Create(HInstance, 'SOCKS', 'DATA');
Dllms := TMemoryStream.Create;
Dllms.LoadFromStream(resStream);
俺为了演示,俺写了一个最古怪的方法。俺把dll的内容写到了pas中。
const
bytecount_line = 32;
bytecount_proc = bytecount_line * 512;
var
ms_dll, ms_uint_proc: TMemoryStream;
p, size, nowsize, nowsize_line, wsize: integer;
s, proc_name: string;
ch: Char;
i, j, k, c: integer;
sl_proc_name: TStringList;
begin
Edit1.Text := trim(Edit1.Text);
if not FileExists(Edit1.Text) then
exit;
ms_dll := TMemoryStream.Create;
ms_uint_proc := TMemoryStream.Create;
ms_dll.LoadFromFile(Edit1.Text);
mycompress(ms_dll);
ms_dll.Position := 0;
sl_proc_name := TStringList.Create;
size := ms_dll.Size;
for i := 1 to (size - 1) div bytecount_proc + 1 do
begin
nowsize := size - ms_dll.Position;
if nowsize > bytecount_proc then
nowsize := bytecount_proc;
proc_name := 'writems_' + IntToStr(i);
sl_proc_name.Add(proc_name);
s := 'procedure ' + proc_name + '(ms: TMemoryStream);'#13#10;
ms_uint_proc.Write(s[1], length(s));
s := 'begin';
ms_uint_proc.Write(s[1], length(s));
wsize := 0;
for j := 1 to (nowsize - 1) div bytecount_line + 1 do
begin
nowsize_line := nowsize - wsize;
if nowsize_line > bytecount_line then
nowsize_line := bytecount_line;
s := '';
s := s + #13#10;
s := s + ' ms.write(';
ms_uint_proc.Write(s[1], length(s));
for k := 1 to nowsize_line do
begin
ms_dll.Read(ch, 1);
s := '#' + IntToStr(ord(ch));
ms_uint_proc.Write(s[1], length(s));
end;
if nowsize_line = 1 then
s := '#0,' + IntToStr(nowsize_line) + ');'
else
s := ',' + IntToStr(nowsize_line) + ');';
ms_uint_proc.Write(s[1], length(s));
inc(wsize, nowsize_line);
end;
s := #13#10'end;'#13#10;
ms_uint_proc.Write(s[1], length(s));
end;
s := 'procedure writems(ms: TMemoryStream);'#13#10;
ms_uint_proc.Write(s[1], length(s));
s := 'begin'#13#10;
ms_uint_proc.Write(s[1], length(s));
for i := 0 to sl_proc_name.Count - 1 do
begin
s := ' ' + sl_proc_name[i] + '(ms);'#13#10;
ms_uint_proc.Write(s[1], length(s));
end;
s := 'end;'#13#10;
ms_uint_proc.Write(s[1], length(s));
s := 'end.'#13#10;
ms_uint_proc.Write(s[1], length(s));
ms_dll.Clear;
s := 'unit DllMemoryStream;'#13#10;
ms_dll.Write(s[1], length(s));
s := 'interface'#13#10;
ms_dll.Write(s[1], length(s));
s := 'uses classes;'#13#10;
ms_dll.Write(s[1], length(s));
s := 'procedure writems(ms: TMemoryStream);'#13#10;
ms_dll.Write(s[1], length(s));
s := 'implementation'#13#10#13#10;
ms_dll.Write(s[1], length(s));
ms_uint_proc.Position := 0;
ms_dll.CopyFrom(ms_uint_proc, ms_uint_proc.Size);
ms_dll.SaveToFile(Edit2.Text);
FreeAndNil(ms_dll);
FreeAndNil(ms_uint_proc);
showmessage('保存成功');
点击按钮会自动生成一个这样的pas文件
unit DllMemoryStream;
interface
uses classes;
procedure writems(ms: TMemoryStream);
implementation
procedure writems_1(ms: TMemoryStream);
begin
ms.write(#0#60#0#0#120#156#237#123#11#116#84#69#182#104#117#247#105#114#72#58#164#129#132#143#2#9#216#32#16#192#254#65,32);
ms.write(#58#116#58#105#242#19#16#180#201#143#111#132#64#58#132#24#67#76#78#39#168#1#58#52#25#57#212#4#112#198#59#207,32);
ms.write(#81#103#6#6#125#131#119#188#51#65#157#153#104#28#108#210#144#128#131#138#168#16#68#1#193#207#137#237#39#35#1#90,32);
ms.write(#18#210#119#239#115#78#119#194#199#59#111#221#245#214#123#235#222#59#39#171#78#85#237#170#218#181#107#239#93#123#239#170,32);
ms.write(#211#89#184#204#65#148#132#16#134#196#144#96#144#144#102#34#61#118#114#7#249#135#143#130#144#215#181#100#72#252#171#131,32);
ms.write(#223#30#223#172#88#240#246#248#93#187#242#74#215#85#39#84#86#173#95#91#85#244#112#194#195#174#106#46#97#181#51#161,32);
ms.write(#202#85#145#224#170#40#118#86#37#44#94#87#97#50#70#71#234#146#254#49#242#255#55#143#35#139#144#5#138#8#50#250,32);
ms.write(#193#244#169#33#216#121#178#99#79#148#66#57#154#76#130#202#48#9#214#100#134#151#150#32#99#164#23#150#149#200#55#233,32);
ms.write(#9#229#100#119#127#69#137#12#10#63#90#105#140#140#134#84#18#146#129#249#42#66#210#85#144#239#130#52#232#54#4#186,32);
ms.write(#9#233#82#254#167#151#247#163#79#198#3#153#89#152#31#209#201#4#77#34#3#22#33#61#9#64#93#230#156#188#57#88,32);
ms.write(#110#194#151#157#136#107#38#83#111#236#7#96#111#122#110#174#88#46#194#53#56#228#134#105#183#76#235#157#177#174#184#136,32);
ms.write(#43#146#215#188#74#158#243#166#126#136#111#134#83#234#39#242#168#82#158#87#127#75#63#199#140#42#103#249#250#53#50#143,32);
ms.write(#220#50#62#227#237#250#85#87#173#193#10#210#23#226#245#172#91#251#221#0#216#45#231#41#255#160#223#127#225#39#56#241,32);
ms.write(#213#85#118#66#189#193#137#77#114#254#146#156#239#147#243#231#229#124#183#156#123#229#252#57#57#127#90#206#159#146#243#93,32);
ms.write(#114#254#83#57#63#46#231#199#228#252#136#156#111#147#243#173#98#158#235#57#244#70#75#36#16#148#39#188#22#12#6#175,32);
ms.write(#100#234#166#41#56#117#204#95#86#232#244#212#231#57#148#185#220#135#125#221#242#152#58#57#223#32#231#156#156#87#202#121,32);
ms.write(#185#156#151#202#121#177#52#71#193#129#227#249#118#226#73#37#174#217#165#153#160#0#101#68#216#7#147#209#35#13#71#93,32);
ms.write(#106#147#247#193#229#190#61#199#160#3#175#224#163#49#55#157#160#173#42#111#99#230#65#134#142#227#71#241#131#210#61#215,32);
ms.write(#138#93#95#211#65#84#203#143#128#190#187#120#194#219#25#31#226#165#223#211#14#225#87#128#170#193#43#35#162#35#120#7,32);
ms.write(#75#11#24#222#161#161#195#121#45#191#132#225#211#25#94#213#164#192#54#7#67#89#62#146#95#196#208#56#36#136#215#238,32);
ms.write(#197#204#151#91#176#56#127#17#253#59#31#171#163#2#45#36#148#209#225#76#208#155#47#96#168#21#230#205#101#85#185#26,32);
ms.write(#107#171#43#150#250#132#191#32#225#25#44#63#136#102#104#20#217#140#63#78#149#205#88#51#88#87#52#180#61#43#182#33,32);
ms.write(#152#158#179#250#93#62#122#146#30#22#10#0#184#213#235#98#76#94#126#208#178#194#149#64#7#206#231#57#20#160#29#180,32);
ms.write(#135#26#1#151#181#171#170#146#190#163#154#207#80#65#245#144#198#250#118#237#106#107#151#235#78#154#206#40#50#88#120#79,32);
ms.write(#201#208#120#30#215#16#215#92#152#33#25#144#249#211#232#59#244#49#70#245#174#220#221#165#158#242#184#198#63#149#70#2,32);
ms.write(#6#94#163#163#143#179#170#199#53#137#63#240#117#58#38#177#139#175#214#208#15#96#224#241#190#16#21#126#77#147#194#207,32);
ms.write(#210#59#173#61#174#122#147#119#169#68#210#46#160#137#126#68#187#234#251#208#42#109#140#56#128#153#95#83#223#134#190#169,32);
ms.write(#254#11#208#215#32#95#205#148#41#74#209#56#21#128#252#2#215#97#169#1#222#218#16#228#238#162#239#55#127#0#124#20,32);
ms.write(#202#165#57#134#151#162#65#40#35#84#229#16#78#67#55#88#184#42#52#71#62#61#13#50#19#218#51#24#156#160#140#17,32);
ms.write(#241#149#98#57#95#120#33#140#210#21#127#243#196#82#199#130#124#193#13#157#120#149#199#74#250#167#189#124#253#150#105#87,32);
ms.write(#203#211#134#215#6#252#254#154#95#160#99#64#198#237#153#58#22#184#24#52#157#224#243#116#26#144#56#163#83#29#230#51,32);
ms.write(#117#90#58#22#209#249#23#129#200#171#89#235#183#181#217#180#77#149#161#177#66#75#173#213#202#233#216#106#134#135#119#8,32);
ms.write(#168#169#97#96#144#70#158#180#64#248#174#87#212#194#200#118#117#19#96#65#7#4#92#223#142#75#58#87#223#131#136#93,32);
ms.write(#191#163#153#58#6#102#213#122#234#116#26#194#141#198#42#205#211#177#188#22#74#154#68#32#11#106#168#174#158#67#177#3,32);
ms.write(#244#164#91#166#155#30#167#95#213#127#78#186#130#65#85#172#174#190#53#24#3#252#185#128#85#88#6#139#184#248#201#240,32);
ms.write(#102#19#15#203#88#232#76#113#57#41#244#65#150#110#210#168#122#172#254#26#37#253#196#90#167#99#107#24#10#111#107#79,32);
ms.write(#205#56#228#43#56#161#196#158#197#185#194#36#121#1#33#42#253#145#116#86#125#159#72#249#27#158#67#26#145#34#220#115,32);
ms.write(#184#87#58#232#37#144#80#140#40#33#164#192#172#163#126#149#76#29#240#147#87#208#195#137#144#205#9#17#97#9#19#49,32);
ms.write(#70#87#173#162#99#116#214#239#170#149#244#58#144#48#166#20#205#186#72#192#191#245#12#228#32#250#149#48#1#94#73#75,32);
ms.write(#27#237#36#180#119#190#167#129#191#126#6#77#245#237#193#52#32#227#75#226#133#153#11#137#223#100#125#92#179#121#26#108,32);
ms.write(#144#83#176#177#132#215#65#35#193#236#112#14#154#45#110#166#236#240#102#74#5#233#124#13#19#250#103#194#78#248#196#117,32);
ms.write(#20#182#106#187#112#181#87#234#62#158#30#19#183#238#69#232#224#73#209#17#215#11#0#0#91#48#72#216#47#41#214#32,32);
ms.write(#121#219#72#252#64#221#130#125#119#141#118#221#150#36#37#206#192#169#173#213#172#235#50#190#22#3#137#49#59#126#1#235,32);
ms.write(#107#4#201#210#83#137#185#26#160#21#180#74#56#131#243#195#182#37#156#9#154#52#141#32#72#160#162#176#71#132#2#209,32);
ms.write(#251#17#74#101#113#11#19#175#139#204#70#89#117#238#10#99#163#109#194#83#97#52#230#1#104#70#132#208#196#52#148#128,32);
ms.write(#250#223#128#234#163#222#48#42#255#92#250#16#107#189#236#154#141#140#156#73#97#93#167#96#240#35#210#92#30#11#225#38,32);
ms.write(#163#125#180#139#236#20#11#33#142#106#129#163#207#92#3#142#70#200#152#66#106#140#251#15#88#68#127#0#37#110#124#90,32);
ms.write(#228#205#69#145#55#102#157#170#11#20#8#138#214#179#213#203#233#187#244#100#226#251#128#228#151#215#69#234#96#45#205#200,32);
ms.write(#78#161#16#144#210#21#58#166#225#12#23#31#166#218#39#234#43#110#28#30#183#17#108#82#200#89#105#213#177#184#98#105,32);
ms.write(#236#147#72#16#154#222#8#160#6#137#201#167#95#155#78#228#151#206#24#101#39#197#65#99#49#63#161#244#85#236#151#252,32);
ms.write(#67#48#232#182#205#116#128#46#114#145#18#104#6#128#36#3#243#83#44#137#232#182#96#73#91#0#165#13#80#42#13#196,32);
ms.write(#136#190#236#227#64#48#184#87#3#80#143#13#223#132#187#167#25#163#44#26#135#53#211#81#126#193#150#110#187#77#1#22,32);
ms.write(#207#245#117#115#55#250#29#59#195#147#189#4#26#219#212#47#161#177#48#121#151#45#93#90#204#107#75#103#2#89#55#145,32);
ms.write(#241#71#64#238#235#204#31#74#136#255#243#221#216#187#16#215#144#235#182#97#153#196#108#61#6#51#225#138#134#141#14#173,32);
ms.write(#232#38#4#37#128#64#154#135#236#65#130#28#130#57#128#74#44#82#44#219#188#97#33#219#153#193#58#132#137#208#76#239,32);
ms.write(#148#141#214#23#18#11#248#64#136#5#155#3#33#22#184#160#36#250#237#6#47#55#18#60#102#28#150#29#194#201#171#97,32);
ms.write(#176#171#51#188#178#209#163#111#89#217#135#208#81#42#189#127#21#215#248#8#88#34#255#153#229#133#190#92#171#26#153#227,32);
ms.write(#26#140#46#56#14#139#232#185#231#178#245#63#160#177#218#108#1#79#60#178#225#232#163#42#207#65#213#193#31#148#226#162,32);
ms.write(#208#152#111#235#246#235#250#193#116#44#194#249#60#218#77#9#175#228#29#12#236#214#80#1#236#8#141#195#53#248#181#116,32);
ms.write(#62#107#61#88#21#161#154#175#129#108#4#29#86#127#13#225#46#65#50#66#42#145#185#180#21#116#152#190#229#233#100#26,32);
ms.write(#199#40#60#215#180#117#49#237#170#8#136#122#233#123#194#107#96#232#151#251#60#215#152#58#13#125#171#254#40#24#45#55,32);
ms.write(#207#242#81#203#125#65#245#115#48#158#30#247#124#197#0#210#11#160#171#155#161#168#136#219#141#235#189#164#38#4#108#135,32);
ms.write(#231#154#166#110#136#231#45#37#108#21#47#35#188#5#155#82#196#20#217#143#73#213#234#73#232#3#63#32#227#129#134#79,32);
ms.write(#177#161#254#7#124#115#178#165#196#200#155#126#84#127#17#231#72#244#209#35#166#161#87#91#193#238#5#67#237#48#25#185,32);
ms.write(#162#80#112#9#136#69#67#171#216#196#54#107#37#27#106#197#120#92#216#14#253#85#103#169#47#108#99#105#135#41#72#85,32);
ms.write(#47#18#156#38#106#34#98#86#5#84#29#84#181#79#233#26#78#47#129#141#89#2#35#104#54#139#80#207#93#125#180#125,32);
ms.write(#128#191#66#67#216#198#232#8#244#250#5#246#234#104#56#19#179#117#11#18#249#16#75#15#131#157#163#199#27#53#73#137,32);
ms.write(#239#193#242#55#51#52#144#216#71#219#18#15#123#2#154#141#177#176#187#21#96#4#32#220#66#155#115#24#205#243#80#17,32);
ms.write(#118#10#150#223#152#205#8#47#3#136#150#235#20#13#223#112#102#250#97#226#73#152#98#13#78#113#88#149#169#83#135#194,32);
ms.write(#180#234#200#198#216#164#196#227#194#175#160#5#44#129#2#253#240#21#216#3#140#78#177#29#76#152#236#202#228#117#130#31,32);
ms.write(#161#231#248#106#48#40#170#54#143#160#225#43#89#8#129#80#203#146#232#201#134#19#160#76#173#170#131#215#36#29#163#153,32);
ms.write(#187#186#65#167#181#98#133#95#177#171#155#95#206#240#119#250#103#131#234#103#48#252#112#136#84#151#49#254#105#48#28#142,32);
ms.write(#45#117#209#162#67#249#74#138#136#70#238#65#37#230#199#138#170#60#160#183#76#135#199#198#160#217#216#100#151#10#154#141,32);
ms.write(#26#73#52#160#99#196#159#184#7#97#158#35#74#26#199#34#18#229#30#204#80#97#126#41#250#162#189#88#133#12#123#73,32);
ms.write(#254#200#115#168#139#118#53#166#232#94#120#129#246#10#187#37#83#207#130#49#21#55#173#246#178#104#76#217#134#51#98#44,32);
ms.write(#152#67#35#172#29#213#145#34#174#41#17#138#123#25#26#161#130#215#37#21#167#211#88#219#170#89#161#11#26#66#96#136,32);
ms.write(#74#135#122#4#230#117#84#56#193#143#78#102#61#3#45#34#5#244#94#70#36#161#73#225#57#164#13#241#87#10#114#63,32);
ms.write(#104#204#96#132#204#128#228#74#185#40#122#72#88#28#14#137#253#202#38#197#210#101#162#143#144#188#122#7#61#214#8#158,32);
ms.write(#214#39#236#29#56#96#210#77#3#36#252#166#19#13#94#144#144#87#117#48#160#180#225#54#216#60#66#178#185#52#111#75,32);
ms.write(#119#195#9#23#43#91#221#175#96#3#139#177#103#215#155#40#129#191#50#162#225#11#0#135#193#29#199#236#216#138#170#25,32);
ms.write(#47#198#225#155#30#71#85#88#206#0#124#115#128#142#228#211#89#107#60#199#240#241#254#53#178#86#68#131#198#53#4#37,32);
ms.write(#165#118#221#15#149#81#18#101#17#38#111#231#54#192#99#117#145#205#207#79#113#17#207#70#16#35#171#114#129#100#248#44,32);
ms.write(#34#138#76#49#83#228#211#201#208#134#151#44#132#231#91#70#49#19#141#130#127#1#44#90#137#250#157#203#210#214#196#54,32);
ms.write(#216#16#96#83#222#87#157#252#153#144#7#50#240#15#163#223#91#227#93#106#10#202#19#33#42#107#66#31#245#253#40#182,32);
ms.write(#66#217#215#1#83#197#221#44#187#11#215#96#161#39#128#4#115#108#61#22#54#111#138#68#2#123#59#243#192#142#153#142,32);
ms.write(#230#151#158#143#71#47#98#40#230#199#223#100#172#19#190#7#113#248#34#60#23#123#61#61#154#141#234#22#13#44#182#190,32);
ms.write(#7#121#18#179#243#231#98#176#219#47#139#129#66#224#30#5#161#182#169#124#72#110#58#99#61#238#186#227#134#158#209#162,32);
ms.write(#241#14#242#117#245#221#254#73#244#111#3#204#183#232#74#249#204#157#221#52#146#95#24#160#11#3#24#77#194#27#2#112,32);
ms.write(#154#195#134#150#13#180#203#43#247#51#138#177#162#113#253#2#78#179#157#40#83#235#88#20#244#230#249#83#196#60#180#183,32);
ms.write(#162#85#98#85#222#49#146#100#198#138#146#121#255#63#64#250#36#32#245#27#65#66#175#226#249#35#171#55#236#215#190#140,32);
ms.write(#191#197#175#93#239#66#111#182#119#48#122#108#154#213#11#146#88#186#180#16#245#21#228#177#72#178#173#222#189#184#191#67,32);
ms.write(#66#137#23#74#174#138#90#52#66#218#247#44#16#223#158#213#139#89#103#145#44#152#159#140#255#17#193#60#129#33#247#37,32);
ms.write(#16#60#29#119#197#167#116#197#72#40#6#227#216#203#120#207#16#45#250#33#159#104#195#97#243#78#81#227#122#174#248#20,32);
ms.write(#92#22#69#131#71#29#44#186#33#246#106#171#10#109#189#60#28#47#4#58#255#140#98#109#75#108#181#58#216#27#224#191,32);
ms.write(#134#151#10#206#138#66#30#104#144#228#118#80#194#52#96#181#33#31#93#211#166#140#149#184#138#12#174#151#108#27#152#196,32);
ms.write(#77#106#97#120#143#24#61#103#245#10#115#128#192#206#6#156#64#123#165#85#201#141#145#61#228#53#38#100#251#162#208#246,32);
ms.write(#37#121#88#133#127#10#109#247#108#128#168#46#10#131#207#65#158#13#172#230#134#62#195#97#5#170#143#132#35#192#65#250,32);
ms.write(#62#108#200#187#33#226#219#131#173#3#165#212#56#254#22#41#45#254#14#165#116#61#98#128#148#10#195#241#60#88#34#79,32);
ms.write(#91#132#231#139#94#79#31#40#251#1#84#118#42#120#190#97#232#70#136#235#197#5#31#86#181#211#14#107#159#43#162#73,32);
ms.write(#209#249#44#200#200#218#23#179#195#131#221#78#37#158#132#56#215#42#178#192#101#129#80#120#138#90#212#46#240#62#234#1,32);
ms.write(#122#24#211#184#0#70#137#80#185#121#138#216#76#175#118#154#176#161#227#138#74#137#119#10#176#58#69#172#78#232#188#34,32);
ms.write(#90#67#77#221#157#244#19#112#212#224#198#142#40#121#21#245#161#31#120#18#150#222#217#135#115#95#237#188#42#201#172#29,32);
ms.write(#131#98#153#134#181#162#3#129#19#43#83#151#139#193#190#60#15#148#164#169#67#27#99#148#216#79#130#169#102#14#216#35,32);
ms.write(#136#79#33#170#13#205#34#19#81#77#162#186#120#23#88#250#206#223#162#35#72#133#72#24#136#58#135#4#47#4#17#180,32);
ms.write(#66#164#134#199#33#141#206#10#65#252#198#33#112#90#165#31#225#250#96#70#255#52#33#254#138#24#182#51#83#96#13#184,32);
ms.write(#160#33#192#202#54#10#75#172#0#109#242#207#86#193#81#18#86#8#49#133#127#70#40#0#25#47#5#32#62#112#14#120,32);
ms.write(#148#241#9#239#254#32#218#176#193#56#109#103#52#158#229#189#254#209#63#74#102#248#172#22#218#127#223#247#219#195#225#130,32);
ms.write(#255#146#184#245#100#59#248#164#28#77#79#212#253#72#52#61#234#27#32#255#36#208#240#190#120#235#192#169#249#194#94#255,32);
ms.write(#44#208#187#157#120#74#9#128#68#4#134#146#208#110#179#118#109#84#210#182#134#32#55#20#78#81#127#123#82#248#94#186,32);
ms.write(#22#184#4#251#128#223#216#175#158#211#116#183#168#103#243#215#168#158#15#170#111#80#79#244#169#13#222#77#113#193#56#157,32);
ms.write(#29#150#137#62#40#170#73#33#184#113#31#40#77#103#168#15#98#48#8#198#161#125#178#220#206#69#53#41#133#85#3#218,32);
ms.write(#249#56#6#154#132#211#176#147#125#210#253#153#251#226#102#143#141#149#230#198#149#5#227#176#178#245#140#43#90#184#56#4,32);
ms.write(#200#125#26#221#189#63#198#221#51#170#22#152#180#221#183#253#105#189#29#117#99#59#120#31#225#223#128#249#34#111#61#231,32);
ms.write(#55#131#16#59#95#196#32#54#151#118#8#251#96#40#47#14#93#238#43#88#204#183#241#167#248#35#201#87#107#135#115#247,32);
ms.write(#128#113#223#48#245#210#11#252#65#207#167#170#75#207#175#124#208#215#200#25#122#27#235#146#123#177#97#232#117#185#197#211,32);
ms.write(#166#242#180#67#59#172#28#233#236#48#93#41#1#215#87#98#219#127#170#234#158#18#219#43#167#106#167#148#76#124#249#84,32);
ms.write(#137#237#229#83#46#112#135#193#220#49#180#171#225#138#84#212#97#145#187#19#100#82#141#183#101#195#234#123#44#176#32#46,32);
ms.write(#178#121#45#170#235#74#244#222#109#161#179#59#223#230#0#134#149#27#188#134#51#111#30#59#118#76#179#125#92#182#187#39,32);
ms.write(#129#11#252#137#184#123#166#115#171#221#61#137#220#74#119#143#14#95#27#184#101#238#158#37#92#190#187#71#239#26#46#246,32);
ms.write(#219#192#205#69#72#198#214#51#92#130#159#129#247#116#183#95#239#238#25#92#59#49#57#80#59#190#145#113#43#188#138#14,32);
ms.write(#232#9#188#252#162#239#109#110#112#131#119#99#158#127#112#182#127#208#213#142#77#247#109#152#183#124#202#89#255#189#125#135,32);
ms.write(#161#131#255#185#55#129#170#24#177#43#119#206#221#83#84#165#114#251#19#36#100#53#81#110#255#80#119#143#186#246#184#219,32);
ms.write(#23#9#120#143#30#60#207#132#176#126#216#247#182#75#121#181#99#169#225#10#111#148#99#174#224#196#55#164#59#87#211#25,32);
ms.write(#56#153#126#11#104#61#129#8#215#152#50#133#112#1#202#19#73#144#16#27#137#6#89#71#136#17#147#75#249#138#2#213,32);
ms.write(#98#151#24#43#116#199#252#69#173#177#163#233#12#52#102#245#58#202#20#101#164#116#242#221#118#82#138#199#13#97#127#167,32);
ms.write(#120#63#179#208#228#205#47#85#220#141#251#67#95#204#39#180#103#117#163#148#27#179#186#29#141#89#1#71#25#156#34#75,32);
ms.write(#51#239#198#77#216#235#16#126#210#137#123#83#214#114#54#4#93#213#137#186#189#5#144#250#191#43#217#131#19#150#76#244,32);
ms.write(#6#75#104#126#160#196#115#33#173#36#170#181#100#47#2#233#231#133#62#146#251#64#118#222#226#57#57#89#43#210#215#87,32);
ms.write(#149#23#85#20#175#200#116#150#87#150#174#91#145#147#183#128#100#59#242#23#22#85#63#84#80#84#238#114#226#157#250#153,32);
ms.write(#139#207#158#158#142#35#65#182#32#213#136#151#21#148#13#46#234#245#185#109#90#0#42#106#134#34#113#64#222#185#107#223,32);
ms.write(#12#9#198#105#65#41#124#187#164#54#194#141#116#56#114#242#202#148#208#250#89#184#213#115#136#93#130#60#205#19#25#113,32);
ms.write(#126#0#156#17#225#33#188#17#142#220#206#14#84#124#128#53#28#229#70#211#57#10#119#114#39#167#113#39#251#93#154#152,32);
ms.write(#3#222#57#115#252#16#213#168#21#7#129#174#208#152#177#142#156#69#194#187#48#104#145#132#253#211#48#246#165#75#151#45,32);
ms.write(#9#209#165#168#25#150#35#181#95#8#183#47#243#57#114#66#173#90#137#228#139#253#141#75#96#14#52#175#87#237#12#158,32);
ms.write(#236#98#26#134#131#55#169#183#156#133#30#212#49#138#206#141#229#42#122#133#247#241#204#20#167#129#254#13#39#98#182#254,32);
ms.write(#29#195#4#8#165#99#182#126#137#230#9#47#69#193#112#215#39#191#115#237#187#33#92#146#240#81#31#94#141#196#34#151,32);
ms.write(#106#166#200#236#170#77#192#11#26#199#34#97#225#151#168#96#100#73#204#214#223#195#88#190#85#188#211#156#171#241#235#195,32);
ms.write(#69#105#168#162#102#92#104#104#156#163#49#83#199#230#44#114#8#90#105#48#172#151#171#244#204#101#148#185#134#51#224#125,32);
ms.write(#139#233#157#185#192#28#160#99#114#25#113#148#154#167#216#73#78#48#46#22#136#165#117#186#201#194#3#96#185#130#226#87,32);
ms.write(#49#126#55#190#233#122#150#174#100#218#239#101#86#65#71#143#79#45#148#224#217#247#98#231#93#184#217#39#64#103#186#77,32);
ms.write(#236#54#148#223#37#230#115#216#206#243#96#186#155#241#134#86#230#21#94#40#201#252#226#226#233#124#166#61#157#105#158#34,32);
ms.write(#93#53#210#50#22#36#39#100#35#206#247#208#141#12#24#167#111#183#51#81#83#193#152#190#1#193#12#149#176#71#242#210,32);
ms.write(#108#233#26#207#42#230#186#196#119#46#154#166#179#194#67#48#169#80#5#47#131#215#115#40#182#152#106#151#210#97#252#208,32);
ms.write(#126#148#160#59#66#245#109#16#177#130#1#6#45#163#197#186#105#6#47#236#35#118#73#161#112#14#32#193#11#62#195#9,32);
ms.write(#186#64#186#192#3#26#139#121#101#240#189#86#13#145#252#28#205#103#169#210#246#51#66#188#155#167#113#43#108#59#176#16,32);
ms.write(#199#45#158#14#254#196#203#173#152#254#4#46#213#54#151#187#223#191#74#253#72#48#152#230#17#148#85#179#56#189#63#199,32);
ms.write(#246#11#236#57#148#179#77#255#57#246#156#49#151#27#62#151#211#249#103#79#191#142#213#123#60#130#141#155#228#159#214#116,32);
ms.write(#196#63#181#233#168#127#82#211#219#254#9#77#239#250#199#65#253#142#166#83#254#17#77#239#248#135#53#117#248#135#52#125,32);
ms.write(#228#143#108#58#237#31#212#244#22#28#215#130#19#131#184#144#28#141#224#6#183#93#216#202#144#27#244#147#71#23#47#171,32);
ms.write(#70#12#104#6#227#16#2#159#137#122#193#61#130#29#123#5#116#166#40#34#212#134#244#196#126#109#88#1#74#106#21#21,32);
ms.write(#59#55#150#102#140#226#198#246#171#244#53#144#23#223#33#41#245#183#168#236#185#26#161#13#209#68#51#14#113#143#2#175,32);
ms.write(#80#201#155#79#35#105#139#98#33#98#235#60#1#33#131#193#139#114#48#156#0#107#86#76#35#129#165#60#11#66#238#5,32);
ms.write(#33#243#165#236#94#29#30#177#197#246#61#88#4#19#51#6#122#37#31#113#177#148#64#95#31#29#236#249#33#200#177#201,32);
ms.write(#10#215#101#74#120#133#120#79#87#176#248#205#4#241#120#204#66#247#185#116#165#134#86#50#24#96#76#157#22#10#48#26,32);
ms.write(#206#108#26#118#31#15#13#153#103#25#232#163#12#30#111#56#179#249#219#144#213#244#199#118#78#7#194#133#38#144#184#240,32);
ms.write(#4#234#208#73#120#129#214#20#138#54#27#240#239#153#44#209#114#31#213#131#139#223#32#98#223#30#198#110#189#180#41#150,32);
ms.write(#50#231#50#248#177#211#164#110#128#223#122#105#243#215#3#240#191#13#209#136#224#64#252#119#35#254#154#48#254#69#5#139,32);
ms.write(#15#32#241#141#27#15#189#134#177#246#165#23#118#170#237#80#223#169#78#193#179#217#116#179#120#169#97#129#247#94#164#129,32);
ms.write(#143#211#99#231#133#135#248#104#28#101#56#234#217#168#1#7#67#89#62#26#231#110#102#181#208#17#141#84#179#22#75#40,32);
ms.write(#67#225#73#20#78#150#198#254#219#185#208#99#238#82#216#165#113#153#80#226#34#82#84#27#85#193#216#250#69#168#225#32,32);
ms.write(#47#22#58#209#124#109#240#189#165#80#72#81#213#97#155#199#54#6#163#22#87#116#155#90#7#5#197#105#155#232#53#178,32);
ms.write(#52#115#99#26#198#195#158#18#62#6#228#160#110#120#246#63#144#7#77#251#181#116#44#193#46#190#55#241#32#243#203#171,32);
ms.write(#65#119#171#30#2#153#131#219#98#7#81#95#139#4#235#161#29#243#32#174#58#179#127#204#30#140#148#232#113#207#133#152,32);
ms.write(#237#63#227#48#228#57#179#253#244#182#216#113#7#5#102#30#184#193#47#164#152#210#224#125#66#141#56#175#118#140#246#218,32);
ms.write(#37#81#175#28#69#215#199#6#107#199#4#107#19#104#146#204#184#149#15#30#149#246#230#34#183#205#44#198#90#139#75#234,32);
ms.write(#109#108#142#157#64#0#19#235#177#105#115#208#188#70#53#51#144#7#227#18#224#93#70#196#205#80#54#174#20#73#47#187,32);
ms.write(#44#188#245#105#48#232#16#62#131#119#168#73#89#234#158#33#54#253#81#108#58#10#239#101#224#236#70#217#197#200#22#252,32);
ms.write(#194#2#40#73#195#137#208#34#182#18#252#242#133#159#86#162#97#181#104#224#90#144#228#3#184#130#55#245#64#151#251#241,32);
ms.write(#201#196#53#194#147#70#32#98#29#201#31#55#157#224#71#82#33#248#33#0#92#223#193#65#65#116#149#67#133#223#3#99,32);
ms.write(#5#163#24#119#239#69#24#140#82#186#34#241#251#174#26#194#232#12#141#160#4#29#2#160#162#70#45#125#78#201#208#130,32);
ms.write(#230#221#33#60#129#39#155#92#45#77#215#90#211#25#46#18#96#131#28#194#84#32#76#120#177#87#26#224#82#65#252#134,32);
ms.write(#68#112#106#97#15#126#188#177#18#215#72#143#109#148#200#178#65#193#56#44#80#24#244#249#121#208#27#85#1#237#162#61,32);
ms.write(#50#135#31#236#172#1#130#196#72#127#47#46#71#24#135#30#121#215#78#53#18#216#217#137#21#170#109#56#193#141#105#23,32);
ms.write(#191#191#211#249#129#121#117#218#174#224#252#128#43#210#209#152#30#16#124#221#193#32#248#93#8#175#117#14#143#55#210#115,32);
ms.write(#190#207#33#236#4#216#178#146#246#76#37#156#174#60#94#118#25#239#232#109#183#7#68#115#13#150#2#191#107#240#62#254,32);
ms.write(#36#255#46#31#16#14#193#4#252#15#124#59#68#158#131#249#86#190#75#136#184#140#38#72#216#134#112#171#164#43#139#29,32);
ms.write(#139#248#83#6#239#247#127#128#160#237#189#37#138#131#75#86#118#226#55#119#95#211#208#206#191#194#76#253#247#53#112#18,32);
ms.write(#217#147#32#197#97#158#141#96#8#147#49#228#122#64#31#10#185#104#97#0#226#168#96#46#19#222#196#145#157#44#156#158,32);
ms.write(#132#22#60#138#101#5#104#104#160#171#93#190#124#0#127#21#55#198#46#126#241#30#35#197#71#120#22#194#19#50#24#139,32);
ms.write(#207#244#33#99#1#88#169#157#17#184#224#128#168#205#175#23#163#54#171#26#7#186#52#216#133#136#72#252#241#123#48#3,32);
ms.write(#33#142#160#90#107#126#175#107#48#205#239#5#159#166#245#15#162#120#247#255#149#175#243#55#120#164#107#21#231#23#215#214,32);
ms.write(#149#11#10#149#223#133#147#22#24#66#147#150#69#52#230#95#206#41#101#180#132#56#132#233#231#130#193#198#172#46#128#188,32);
ms.write(#134#183#159#194#81#209#62#64#189#87#184#191#27#175#221#60#27#123#9#7#103#153#48#125#133#128#8#70#8#241#125#24,32);
ms.write(#84#78#199#25#187#32#162#197#224#17#191#245#0#227#254#96#8#49#46#168#126#30#191#105#220#213#140#7#2#225#5#56,32);
ms.write(#249#137#27#78#120#22#75#199#115#209#30#65#73#120#238#139#1#235#255#19#140#246#117#226#183#10#127#0#108#162#103#58,32);
ms.write(#162#80#196#120#14#3#121#109#106#22#56#160#108#87#163#85#67#243#214#174#70#171#134#230#173#77#61#203#33#54#17#200,32);
ms.write(#52#192#67#161#172#91#58#48#10#79#118#163#189#5#245#40#105#87#167#64#107#211#41#40#160#41#16#11#31#228#98#65,32);
ms.write(#24#115#54#24#220#59#13#201#92#134#165#201#88#154#123#22#35#120#116#151#226#177#120#186#144#132#0#244#174#37#158#0,32);
ms.write(#83#163#105#87#239#147#191#89#248#19#132#75#159#192#44#63#1#166#236#69#160#63#70#184#128#0#87#8#32#182#239#77,32);
ms.write(#16#99#224#224#196#175#229#223#107#8#114#254#153#156#159#151#243#143#229#188#67#204#29#101#118#225#136#28#239#54#179#82,32);
ms.write(#60#148#43#124#47#95#139#114#179#60#182#173#192#150#160#43#178#249#2#202#240#81#116#188#62#161#77#250#153#134#70#2,32);
ms.write(#22#3#208#175#113#236#193#158#14#225#183#208#182#220#39#226#2#125#138#23#30#131#250#94#108#18#158#135#146#220#201#133,32);
ms.write(#192#21#178#15#14#245#29#39#79#198#197#201#189#30#16#167#65#195#50#29#73#12#245#27#45#126#95#9#117#142#146#59,32);
ms.write(#223#33#218#136#237#209#11#240#42#16#65#91#143#186#38#21#211#56#252#97#20#101#182#248#132#137#253#211#95#233#19#17,32);
ms.write(#43#124#123#68#26#192#6#73#128#51#190#230#109#72#233#51#189#136#235#117#44#131#227#83#184#166#58#114#218#212#136#88,32);
ms.write(#65#23#130#11#116#160#135#196#216#18#9#34#237#233#120#167#68#132#131#128#127#217#146#224#204#60#104#125#109#55#162#121,32);
ms.write(#2#191#247#137#251#5#117#55#203#220#175#187#75#196#43#25#89#45#23#152#81#45#83#47#75#106#9#231#239#233#216#44,32);
ms.write(#198#28#37#52#139#45#81#101#105#10#91#89#178#75#198#243#68#24#79#24#195#14#17#67#111#183#132#1#181#230#105#128,32);
ms.write(#56#32#37#64#106#198#77#3#9#159#82#179#120#119#233#57#116#168#121#151#25#239#64#48#86#120#19#108#77#163#212#254,32);
ms.write(#207#231#63#255#40#129#135#198#225#212#75#144#151#161#36#63#197#227#236#164#59#30#162#161#187#0#246#183#99#71#142#158,32);
ms.write(#122#247#200#219#239#156#233#248#232#244#91#31#127#114#246#220#249#79#47#146#207#62#135#254#89#85#85#235#171#96#95#230,32);
ms.write(#184#42#184#117#15#59#19#156#88#79#192#167#136#75#208#203#15#180#235#13#70#147#121#230#172#36#75#242#156#244#140#204,32);
ms.write(#172#108#140#5#126#140#174#82#147#157#196#66#58#110#180#19#187#201#254#99#221#254#249#252#95#120#186#87#129#172#87#221,32);
ms.write(#8#171#91#77#200#27#55#193#246#1#236#200#77#48#1#96#29#55#193#66#143#178#136#144#59#32#25#33#205#135#84#2,32);
ms.write(#9#127#219#185#21#210#46#72#191#134#244#18#164#86#72#31#64#250#2#82#0#82#36#224#28#5#105#18#36#35#164#251,32);
ms.write(#33#45#131#84#190#90#194#187#13#242#103#228#242#159#33#127#11#210#71#114#253#10#228#204#26#66#134#65#26#3#105#50,32);
ms.write(#36#243#26#169#237#33#103#85#133#179#220#100#156#81#92#94#142#245#76#103#185#147#115#102#84#173#227#214#173#41#42#207,32);
ms.write(#117#174#225#214#173#175#0#248#2#103#81#205#109#192#36#171#130#115#86#221#6#62#175#2#64#69#229#235#30#187#205#160,32);
ms.write(#130#117#85#156#171#168#60#187#202#233#236#175#205#41#23#127#187#10#51#173#95#19#110#19#203#225#150#123#157#92#129#179,32);
ms.write(#170#90#158#1#106#25#174#170#42#103#5#151#87#90#229#44#42#158#87#44#67#165#170#56#212#41#65#114#185#34#152#163,32);
ms.write(#114#94#69#201#250#57#18#68#106#13#1#68#92#235#31#126#184#168#162#120#193#186#10#39#130#144#128#5#235#86#87#21,32);
ms.write(#85#61#138#171#220#176#142#115#84#173#95#227#172#174#134#218#98#88#145#51#123#157#136#61#191#162#20#70#149#59#139#179,32);
ms.write(#54#172#113#86#226#2#161#1#88#130#88#115#184#242#252#138#218#117#21#72#88#78#209#186#106#103#184#15#9#209#85#60,32);
ms.write(#87#28#13#103#131#106#103#85#191#20#160#237#62#231#163#171#215#23#85#21#231#61#90#137#243#44#132#169#139#214#58#211,32);
ms.write(#215#111#152#67#138#138#107#138#42#215#245#247#206#113#174#93#228#114#86#61#42#94#186#101#109#152#35#195#30#168#116#86,32);
ms.write(#0#22#9#0#245#140#242#245#213#78#0#220#34#243#188#242#234#92#96#173#124#101#7#181#123#111#168#201#178#128#210#255,32);
ms.write(#129#140#254#187#60#198#74#241#39#253#225#52#25#234#211#32#233#33#45#49#19#50#27#127#135#77#128#129#34#19#215#246,32);
ms.write(#51#236#159#207#127#221#7#142#59#99#64#216#74#125#164#126#152#254#14#253#4#253#84#189#81#63#91#159#174#159#175#207,32);
ms.write(#209#47#211#175#214#151#233#171#244#143#233#183#232#255#160#255#179#254#128#190#77#255#142#254#164#254#172#254#11#253#119#122,32);
ms.write(#173#97#148#193#109#120#194#240#174#49#219#244#47#112#20#250#214#84#108#222#103#238#52#143#157#57#101#102#230#204#83#51,32);
ms.write(#39#37#173#78#218#156#180#61#233#95#146#126#149#244#187#164#253#73#45#73#239#37#157#74#250#60#41#144#164#180#176#150,32);
ms.write(#17#150#49#22#157#101#150#37#221#178#200#82#104#113#90#42#45#53#22#143#133#183#236#181#252#171#229#85#203#1#203#17,32);
ms.write(#203#7#150#115#150#46#203#21#75#159#133#77#142#79#158#154#124#95#242#154#228#45#201#207#36#255#54#249#66#114#32#249,32);
ms.write(#222#217#107#103#55#204#254#163#245#13#235#119#214#203#214#33#41#35#83#18#82#18#83#204#41#214#148#249#41#139#82#170,32);
ms.write(#83#142#165#124#144#178#212#86#107#171#179#109#177#125#107#235#182#49#169#209#169#57#169#203#83#31#73#253#95#169#123#83,32);
ms.write(#127#159#122#54#149#77#155#144#182#32#45#63#205#153#246#112#90#117#90#93#154#39#109#91#218#142#180#61#105#255#154#118,32);
ms.write(#36#237#157#180#147#105#248#83#223#4#220#8#250#65#250#81#16#186#164#232#51#245#203#129#31#143#233#159#209#191#44#114,32);
ms.write(#225#51#253#87#250#49#6#187#225#65#67#133#129#51#212#25#62#53#124#109#184#108#232#49#68#25#99#141#78#99#185#177,32);
ms.write(#206#248#19#227#79#141#79#25#159#49#238#54#254#206#184#223#184#196#84#111#250#141#233#247#166#87#76#209#230#225#230#59,32);
ms.write(#205#105#230#149#230#199#204#59#205#207#153#223#48#63#60#115#217#172#95#206#122#113#214#155#179#62#153#117#105#86#100#82,32);
ms.write(#124#210#210#164#138#164#45#192#191#221#73#205#73#109#73#215#146#70#88#38#0#191#236#150#92#224#83#147#229#53#139#223,32);
ms.write(#210#109#153#146#172#79#206#73#254#77#114#123#114#140#53#201#154#106#45#176#110#176#190#100#125#213#250#166#213#111#37#41,32);
ms.write(#247#165#60#152#82#149#178#47#165#57#229#64#202#161#148#183#82#222#77#249#48#229#108#202#183#41#151#82#2#41#215#83,32);
ms.write(#148#54#173#237#14#91#150#237#126#91#190#173#210#182#193#246#188#237#143#182#99#182#147#182#30#155#58#53#38#117#100#234,32);
ms.write(#216#212#196#212#108#224#152#51#181#44#149#79#221#145#250#243#212#63#165#30#77#157#145#150#148#86#152#86#150#70#196#255,32);
ms.write(#199#120#14#178#241#160#49#85#250#71#245#84#255#34#240#229#128#254#176#158#24#230#25#30#50#212#26#54#25#182#25#126,32);
ms.write(#102#120#209#240#186#161#221#240#142#225#132#161#195#240#177#225#130#161#211#240#141#33#194#168#53#142#54#78#52#222#99#44,32);
ms.write(#48#62#36#242#105#135#241#23#198#95#27#255#183#241#15#198#63#27#207#26#89#211#93#166#233#38#139#233#62#83#174#105,32);
ms.write(#131#201#109#218#97#250#185#233#37#211#27#166#183#77#167#77#95#154#254#110#138#49#199#154#239#54#155#204#118#115#142#121,32);
ms.write(#189#121#139#249#41#243#211#192#197#221#230#231#205#47#153#255#130#255#171#99#135#216#1#50#157#126#178#126#154#126#183#254,32);
ms.write(#121#253#62#253#75#250#255#96#31#252#15#126#70#221#183#112#169#84#82#137#167#246#201#112#170#199#75#72#59#228#67#136,32);
ms.write(#248#111#58#238#27#251#41#68#255#176#225#38#56#222#231#141#82#16#247#46#128#79#130#124#223#77#237#56#38#21#224#222,32);
ms.write(#219#224#99#224#56#218#113#11#61#210#255#79#9#63#2#15#220#6#142#120#88#104#118#60#9#227#148#253#107#180#60#21,32);
ms.write(#254#247#43#241#153#251#148#184#206#240#83#9#245#216#1#245#65#36#147#20#144#12#178#128#204#129#20#69#28#144#103#144,32);
ms.write(#251#224#125#47#201#34#243#200#253#36#155#60#64#88#178#16#32#88#155#7#173#15#64#142#56#19#36#222#33#53#18#178,32);
ms.write(#1#116#220#248#184#37#78#184#221#82#134#127#8#130#151#215#11#92#194#175#164#120#50#130#227#145#152#225#31#130#224#21,32);
ms.write(#101#24#138#79#120#73#81#45#38#120#12#225#58#187#141#34#160#127#201#88#51#13#237#159#122#219#182#109#45#45#251#7,32);
ms.write(#208#34#142#39#76#102#166#92#167#45#175#236#39#76#118#77#77#102#184#110#32#247#174#93#91#82#99#151#16#208#87#12,32);
ms.write(#202#73#53#53#107#215#22#203#20#64#189#182#118#237#234#26#46#92#175#173#173#173#154#176#182#196#46#81#212#34#213#107,32);
ms.write(#100#4#45#45#166#81#80#13#181#135#235#147#74#194#19#140#170#173#157#80#59#97#130#84#103#1#225#206#218#170#187#7,32);
ms.write(#214#159#184#10#205#186#208#146#91#12#85#128#160#39#244#111#108#128#112#228#221#181#19#238#105#10#45#153#154#70#78#168,32);
ms.write(#173#213#181#132#120#68#95#209#42#39#76#32#81#77#225#186#65#26#24#26#208#98#144#86#210#20#170#35#67#163#90#90,32);
ms.write(#90#42#67#76#55#136#117#66#94#65#246#89#197#58#193#186#40#14#83#203#43#38#177#222#68#90#176#3#12#52#17#105,32);
ms.write(#0#109#193#103#91#203#43#18#161#205#116#155#248#80#185#222#180#77#126#90#164#121#200#141#79#19#113#43#130#193#80#242,32);
ms.write(#170#164#212#165#242#4#187#134#144#96#151#134#108#238#98#73#90#0#19#33#241#152#122#7#164#62#41#165#97#10#74#41,32);
ms.write(#62#88#239#217#25#116#7#219#131#222#94#85#208#187#73#17#60#159#26#3#77#17#144#192#36#164#213#67#242#66#58#8,32);
ms.write(#233#34#232#223#213#73#182#7#44#173#91#146#154#47#233#210#85#35#159#157#237#129#45#247#83#164#12#237#135#226#111#98,32);
ms.write(#144#93#159#251#104#53#30#137#8#105#135#18#231#124#88#162#29#109#71#66#2#35#238#14#220#161#10#242#207#231#255#223,32);
ms.write(#243#239#51#0#66#134,6);
end;
procedure writems(ms: TMemoryStream);
begin
writems_1(ms);
end;
end.
在exe中调用内存中的函数
在工程中引用上面产生的那个pas文件。
按钮对应的代码为:
var
Dllms: TMemoryStream;
MyLibrary: TLibInfo;
begin
Dllms := TMemoryStream.Create;
writems(Dllms);
myUNcompress(Dllms);
Dllms.Position := 0;
MyLibrary := xLoadLibrary(Dllms.Memory, MyImports);
showmessage(inttostr( getValue(5,1)));
xFreeLibrary(MyLibrary);
FreeAndNil(Dllms);
exe的完整代码如下:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, zlib;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses DllMemoryStream, DLLUnit;
{$R *.dfm}
var
getValue: function(p1, p2: word): word; stdcall;
MyImports: array[0..0] of TImportItem = ((Name: 'getValue'; PProcVar: @@getValue));
procedure myUNcompress(V: Tmemorystream);
var
mysize: integer;
myUNCompression: TDecompressionStream;
temp: pchar;
begin
v.Position := 0;
v.ReadBuffer(mysize, sizeof(mysize));
myUNCompression := TDecompressionStream.Create(v);
getmem(temp, mysize);
myUNCompression.ReadBuffer(temp^, mysize);
freeandnil(myUNCompression);
v.Clear;
v.WriteBuffer(temp^, mysize);
freemem(temp);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
Dllms: TMemoryStream;
MyLibrary: TLibInfo;
begin
Dllms := TMemoryStream.Create;
writems(Dllms);
myUNcompress(Dllms);
Dllms.Position := 0;
MyLibrary := xLoadLibrary(Dllms.Memory, MyImports);
showmessage(inttostr( getValue(5,1)));
xFreeLibrary(MyLibrary);
FreeAndNil(Dllms);
end;
end.
调用的核心处理在 DLLUnit中
在
{
DLL Loader by Aphex
http://www.iamaphex.cjb.net
unremote@knology.net
Based on code from gmm@ufacom.ru
function xLoadLibrary(Src: Pointer; Imports: array of TImportItem): TLibInfo;
procedure xFreeLibrary(hModule: TLibInfo);
}
unit DLLUnit;
interface
uses
Windows;
type
TImportItem = record
Name: string;
PProcVar: ^Pointer;
end;
TwordArr = array[0..0] of word;
PwordArr = ^TwordArr;
TdwordArr = array[0..0] of dword;
PdwordArr = ^TdwordArr;
PImageImportDescriptor = ^TImageImportDescriptor;
TImageImportDescriptor = packed record
OriginalFirstThunk: dword;
TimeDateStamp: dword;
ForwarderChain: dword;
Name: dword;
FirstThunk: dword;
end;
PImageBaseRelocation = ^TImageBaseRelocation;
TImageBaseRelocation = packed record
VirtualAddress: cardinal;
SizeOfBlock: cardinal;
end;
TDllEntryProc = function(hinstDLL: HMODULE; dwReason: dword; lpvReserved: Pointer): Boolean; stdcall;
TStringArray = array of string;
TLibInfo = record
ImageBase: Pointer;
DllProc: TDllEntryProc;
LibsUsed: TStringArray;
end;
PLibInfo = ^TLibInfo;
PPointer = ^Pointer;
TSections = array[0..100000] of TImageSectionHeader;
const
IMPORTED_NAME_OFFSET = $00000002;
IMAGE_ORDINAL_FLAG32 = $80000000;
IMAGE_ORDINAL_MASK32 = $0000FFFF;
function xLoadLibrary(Src: Pointer; Imports: array of TImportItem): TLibInfo;
function xFreeLibrary(LoadedLib: TLibInfo): boolean;
implementation
function xFreeLibrary(LoadedLib: TLibInfo): boolean;
var
ObjectLoop: integer;
begin
Result := False;
with LoadedLib do
begin
if @DllProc <> nil then
begin
DllProc(HModule(LoadedLib.ImageBase), DLL_PROCESS_DETACH, nil);
end;
for ObjectLoop := 0 to Length(LibsUsed) - 1 do
begin
if ObjectLoop >= Length(LibsUsed) then Exit;
FreeLibrary(GetModuleHandle(pchar(LibsUsed[ObjectLoop])));
end;
SetLength(LibsUsed, 0);
end;
VirtualFree(LoadedLib.ImageBase, 0, MEM_RELEASE);
Result := True;
end;
function xLoadLibrary(Src: Pointer; Imports: array of TImportItem): TLibInfo;
var
ImageBase: pointer;
ImageBaseDelta: integer;
ImageNtHeaders: PImageNtHeaders;
PSections: ^TSections;
SectionLoop: integer;
SectionBase: pointer;
VirtualSectionSize, RawSectionSize: cardinal;
OldProtect: cardinal;
NewLibInfo: TLibInfo;
function StrToInt(S: string): integer;
begin
Val(S, Result, Result);
end;
procedure Add(Strings: TStringArray; Text: string);
begin
SetLength(Strings, Length(Strings) + 1);
Strings[Length(Strings) - 1] := Text;
end;
function Find(Strings: array of string; Text: string; var Index: integer): boolean;
var
StringLoop: integer;
begin
Result := False;
for StringLoop := 0 to Length(Strings) - 1 do
begin
if lstrcmpi(pchar(Strings[StringLoop]), pchar(Text)) = 0 then
begin
Index := StringLoop;
Result := True;
end;
end;
end;
function GetSectionProtection(ImageScn: cardinal): cardinal;
begin
Result := 0;
if (ImageScn and IMAGE_SCN_MEM_NOT_CACHED) <> 0 then
begin
Result := Result or PAGE_NOCACHE;
end;
if (ImageScn and IMAGE_SCN_MEM_EXECUTE) <> 0 then
begin
if (ImageScn and IMAGE_SCN_MEM_READ) <> 0 then
begin
if (ImageScn and IMAGE_SCN_MEM_WRITE) <> 0 then
begin
Result := Result or PAGE_EXECUTE_READWRITE
end
else
begin
Result := Result or PAGE_EXECUTE_READ
end;
end
else
if (ImageScn and IMAGE_SCN_MEM_WRITE) <> 0 then
begin
Result := Result or PAGE_EXECUTE_WRITECOPY
end
else
begin
Result := Result or PAGE_EXECUTE
end;
end
else
if (ImageScn and IMAGE_SCN_MEM_READ) <> 0 then
begin
if (ImageScn and IMAGE_SCN_MEM_WRITE) <> 0 then
begin
Result := Result or PAGE_READWRITE
end
else
begin
Result := Result or PAGE_READONLY
end
end
else
if (ImageScn and IMAGE_SCN_MEM_WRITE) <> 0 then
begin
Result := Result or PAGE_WRITECOPY
end
else
begin
Result := Result or PAGE_NOACCESS;
end;
end;
procedure ProcessExports(PExports: PImageExportDirectory; BlockSize: cardinal);
var
ExportLoop: byte;
ImportedFn: cardinal;
PFnName: pchar;
FnIndex: dword;
function IsForwarderString(Data: pchar): boolean;
begin
Result := Data > PExports;
if Result then Result := cardinal(Data - PExports) < BlockSize;
end;
function GetForwardedSymbol(ForwarderString: pchar): pointer;
var
sForwarderString, DllName: string;
ForwarderLoop: integer;
LibHandle: HModule;
begin
sForwarderString := ForwarderString;
while ForwarderString^ <> '.' do
begin
Inc(ForwarderString);
end;
DllName := Copy(sForwarderString, 1, pos('.', sForwarderString) - 1);
if not Find(NewLibInfo.LibsUsed, DllName, ForwarderLoop) then
begin
LibHandle := LoadLibrary(pchar(DllName));
Add(NewLibInfo.LibsUsed, DllName);
end
else
begin
LibHandle := cardinal(NewLibInfo.LibsUsed[ForwarderLoop]);
end;
if ForwarderString^ = '#' then ForwarderString := pointer(StrToInt((ForwarderString + 1)));
Result := GetProcAddress(LibHandle, ForwarderString);
end;
begin
for ExportLoop := 0 to PExports.NumberOfNames - 1 do
begin
PFnName := pchar(PdwordArr(cardinal(PExports.AddressOfNames) + cardinal(ImageBase))^[ExportLoop] + cardinal(ImageBase));
for ImportedFn := low(Imports) to high(Imports) do
begin
if Imports[ImportedFn].Name = PFnName then
begin
FnIndex := PwordArr(cardinal(PExports.AddressOfNameOrdinals) + cardinal(ImageBase))^[ExportLoop];
Imports[ImportedFn].PProcVar^ := pointer(PdwordArr(cardinal(PExports.AddressOfFunctions) + cardinal(ImageBase))^[FnIndex] + cardinal(ImageBase));
if IsForwarderString(Imports[ImportedFn].PProcVar^) then
begin
Imports[ImportedFn].PProcVar^ := GetForwardedSymbol(Imports[ImportedFn].PProcVar^);
end;
end;
end;
end;
end;
procedure ProcessRelocs(PRelocs: PImageBaseRelocation);
var
PReloc: PImageBaseRelocation;
RelocsSize: cardinal;
Reloc: PWord;
ModCount: cardinal;
RelocLoop: cardinal;
begin
PReloc := PRelocs;
RelocsSize := ImageNtHeaders.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC].Size;
while cardinal(PReloc) - cardinal(PRelocs) < RelocsSize do
begin
ModCount := (PReloc.SizeOfBlock - Sizeof(PReloc^)) div 2;
Reloc := pointer(cardinal(PReloc) + sizeof(PReloc^));
for RelocLoop := 0 to ModCount - 1 do
begin
if Reloc^ and $F000 <> 0 then Inc(pdword(cardinal(ImageBase) + PReloc.VirtualAddress + (Reloc^ and $0FFF))^, ImageBaseDelta);
Inc(Reloc);
end;
PReloc := pointer(Reloc);
end;
end;
procedure ProcessImports(PImports: PImageImportDescriptor);
var
PImport: PImageImportDescriptor;
Import: LPDword;
PImportedName: pchar;
LibHandle: HModule;
ProcAddress: pointer;
PLibName: pchar;
ImportLoop: integer;
function IsImportByOrdinal(ImportDescriptor: dword; HLib: THandle): boolean;
begin
Result := (ImportDescriptor and IMAGE_ORDINAL_FLAG32) <> 0;
end;
begin
PImport := PImports;
while PImport.Name <> 0 do
begin
PLibName := pchar(cardinal(PImport.Name) + cardinal(ImageBase));
if not Find(NewLibInfo.LibsUsed, PLibName, ImportLoop) then
begin
LibHandle := LoadLibrary(PLibName);
Add(NewLibInfo.LibsUsed, PLibName);
end
else
begin
LibHandle := cardinal(NewLibInfo.LibsUsed[ImportLoop]);
end;
if PImport.TimeDateStamp = 0 then
begin
Import := LPDword(pImport.FirstThunk + cardinal(ImageBase))
end
else
begin
Import := LPDword(pImport.OriginalFirstThunk + cardinal(ImageBase));
end;
while Import^ <> 0 do
begin
if IsImportByOrdinal(Import^, LibHandle) then
begin
ProcAddress := GetProcAddress(LibHandle, pchar(Import^ and $FFFF))
end
else
begin
PImportedName := pchar(Import^ + cardinal(ImageBase) + IMPORTED_NAME_OFFSET);
ProcAddress := GetProcAddress(LibHandle, PImportedName);
end;
PPointer(Import)^ := ProcAddress;
Inc(Import);
end;
Inc(PImport);
end;
end;
begin
ImageNtHeaders := pointer(int64(cardinal(Src)) + PImageDosHeader(Src)._lfanew);
ImageBase := VirtualAlloc(nil, ImageNtHeaders.OptionalHeader.SizeOfImage, MEM_RESERVE, PAGE_NOACCESS);
ImageBaseDelta := cardinal(ImageBase) - ImageNtHeaders.OptionalHeader.ImageBase;
SectionBase := VirtualAlloc(ImageBase, ImageNtHeaders.OptionalHeader.SizeOfHeaders, MEM_COMMIT, PAGE_READWRITE);
Move(Src^, SectionBase^, ImageNtHeaders.OptionalHeader.SizeOfHeaders);
VirtualProtect(SectionBase, ImageNtHeaders.OptionalHeader.SizeOfHeaders, PAGE_READONLY, OldProtect);
PSections := pointer(pchar(@(ImageNtHeaders.OptionalHeader)) + ImageNtHeaders.FileHeader.SizeOfOptionalHeader);
for SectionLoop := 0 to ImageNtHeaders.FileHeader.NumberOfSections - 1 do
begin
VirtualSectionSize := PSections[SectionLoop].Misc.VirtualSize;
RawSectionSize := PSections[SectionLoop].SizeOfRawData;
if VirtualSectionSize < RawSectionSize then
begin
VirtualSectionSize := VirtualSectionSize xor RawSectionSize;
RawSectionSize := VirtualSectionSize xor RawSectionSize;
VirtualSectionSize := VirtualSectionSize xor RawSectionSize;
end;
SectionBase := VirtualAlloc(PSections[SectionLoop].VirtualAddress + pchar(ImageBase), VirtualSectionSize, MEM_COMMIT, PAGE_READWRITE);
FillChar(SectionBase^, VirtualSectionSize, 0);
Move((pchar(src) + PSections[SectionLoop].PointerToRawData)^, SectionBase^, RawSectionSize);
end;
NewLibInfo.DllProc := TDllEntryProc(ImageNtHeaders.OptionalHeader.AddressOfEntryPoint + cardinal(ImageBase));
NewLibInfo.ImageBase := ImageBase;
SetLength(NewLibInfo.LibsUsed, 0);
if ImageNtHeaders.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC].VirtualAddress <> 0 then
ProcessRelocs(pointer(ImageNtHeaders.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC].VirtualAddress + cardinal(ImageBase)));
if ImageNtHeaders.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress <> 0 then
ProcessImports(pointer(ImageNtHeaders.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress + cardinal(ImageBase)));
for SectionLoop := 0 to ImageNtHeaders.FileHeader.NumberOfSections - 1 do
begin
VirtualProtect(PSections[SectionLoop].VirtualAddress + pchar(ImageBase), PSections[SectionLoop].Misc.VirtualSize, GetSectionProtection(PSections[SectionLoop].Characteristics), OldProtect);
end;
if @NewLibInfo.DllProc <> nil then
begin
if not NewLibInfo.DllProc(cardinal(ImageBase), DLL_PROCESS_ATTACH, nil) then
begin
NewLibInfo.DllProc := nil;
xFreeLibrary(Result);
end;
end;
if ImageNtHeaders.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress <> 0 then
ProcessExports(pointer(ImageNtHeaders.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress + cardinal(ImageBase)),
ImageNtHeaders.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].Size);
Result := NewLibInfo;
end;
end.