我想编写一个程序来读取/提取.exe文件中的所有有效字符串(例如:“该程序必须在Win下运行”或“MZ”),与sysinternals
的Strings.exe
完全相同。 其实我想扫描.exe
文件,如果它包含特殊的字符串值,如"ekrn.exe"
或"Filrefox.exe"
然后检测到该文件为可疑文件(杀死ekrn.exe
或注入malcode firefox.exe
)。从德尔福的.exe文件(如Strings.exe)中读取字符串
我写在Delphi下面的代码:
const
TargetName = 'E:\AntiDebugg.exe';
var
hFile: THandle;
tmp: AnsiString;
dwFileSize, lChar, lSearch: Integer;
dwNumRead: Cardinal;
dwBuffer: array of AnsiChar;
begin
mmo1.Clear;
hFile := CreateFileA(TargetName, GENERIC_READ, FILE_SHARE_READ, nil,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
dwFileSize := GetFileSize(hFile, nil);
SetLength(dwBuffer, dwFileSize);
lChar := 0;
lSearch := 0;
while lChar <= dwFileSize do
begin
ReadFile(hFile, dwBuffer[lChar], SizeOf(dwBuffer), dwNumRead, nil);
while dwBuffer[lChar] <> '' do
begin
tmp := tmp + dwBuffer[lChar];
Inc(lChar, 1);
end;
lSearch := 0;
Inc(lChar, 1);
end;
mmo1.Text := (tmp);
CloseHandle(hFile);
运行我的代码的结果是(一小块):
MZPےے¸@؛´ ح!¸Lح!گگThis program must be run under Win32
$7PEL
%0فQà´أ\
¤"0Bگب.textd .itext| .data`@.bssطN.idata\
@.didataب@[email protected]¤"@[email protected]@@[email protected]@[email protected] Charے[email protected]ے€@Byteک@Wordے°@Pointerؤ@Cardinalےےےà@ NativeIntےےےü@
NativeUIntے@ShortStringے,@ [email protected]@[email protected]Œ@[email protected]ے€@TGUID
但是这不是我想要的结果,我的期望结果是:
MZP
This program must be run under Win32
.text
`.itext
`.data
.bss
.idata
.didata
.tls
.rdata
@.reloc
B.rsrc
Boolean
False
True
System
AnsiChar
Char
Integer
Byte
Word
Pointer
Cardinal
NativeInt
NativeUInt
ShortString
PAnsiChar0
string
TClass
HRESULT
TGUID
- 在此示例吨他编写的Delphi
AntiDebugg.exe
。
的Strings.exe
为 “AntiDebugg.exe”
任何想法的字符串的结果? 我该怎么办?
你不这样做['字符串(1)'](HTTP:// www.freebsd.org/cgi/man.cgi?query=strings&sektion=1)。请考虑阅读整个说明。 –
['ASCII range'](http://www.asciitable.com/)中的一些字符是不可显示的。 1)从第一个可显示的字符中扫描缓冲区,直到达到无法显示的字符(或者,您不想显示的字符)。这是你可以存储在某个地方的一个词。 2)转到步骤1 – TLama
要特别注意第一条评论中提到的链接中的“可打印字符”。你为什么偶尔给lSearch分配0? –