|
-
June 21st, 2010, 08:36 AM
#1
[RESOLVED] store a string in an executable
hello,
maybe someone can give me a brief instruction how to achieve this best:
I would like to program a tool which stores a string in an executable. This string should somehow be created from for example the size of the executable and the checksum or something like that. But that's not that important at the moment.
I just want to know how to store that string and how to find it again in the exe to verify it. And this exe should of course be still executable.
I would appreciate any help.
Kind regards
-
June 21st, 2010, 09:15 AM
#2
Re: store a string in an executable
Since you're posting in the WinAPI forum, I'll assume this is a windows exe. The easiest way I could think of is to store the string as a resource the same as an icon or a bitmap.
Alternatively, you could declare a new section in the PE executable structure with a pragma:
Code:
#pragma code_seg(push, rl,".mysection")
const char MyString[]="Hello Hackers!";
#pragma code_seg(pop)
then, after compilation, parse the exe file for that section, but the PE structure is rather complicated and difficult to parse.
-
June 21st, 2010, 09:38 AM
#3
Re: store a string in an executable
thank you for your answer.
yes, it is a windows exe. Storing it as a resource sounds good. But how can I programmatically add a resource to a different executable? Is that possible?
I started to read
http://www.codeguru.com/cpp/w-p/win3...table-File.htm
and this PE structure really seems to be rather complicated. But the sample projects at the end of the page may be usefull at least.
-
June 21st, 2010, 11:24 AM
#4
Re: store a string in an executable
You can get a module handle to any EXE with LoadLibrary(). With that handle, you can call FindResource(), LoadResource(), then LockResource() will get you a memory pointer to the raw resource and SizeOfResource() will get you the length.
-
June 21st, 2010, 05:43 PM
#5
Re: store a string in an executable
 Originally Posted by Makiman
I would like to program a tool which stores a string in an executable. This string should somehow be created from for example the size of the executable and the checksum or something like that...
You already have such a tool – linker.
Check out its /RELEASE option.
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio:
FeinWindows - replacement windows manager for Visual Studio, and more...
-
June 22nd, 2010, 06:44 AM
#6
Re: store a string in an executable
i did the following and it seems to be exactly what I need
for storing:
Code:
HGLOBAL hResLoad;
HMODULE hExe;
HRSRC hRes;
HANDLE hUpdateRes;
TCHAR *lpResLock;
BOOL result;
hUpdateRes = BeginUpdateResource(_T("c:\\Example_1.exe"),false);
TCHAR* str = _T("abc123");
result = UpdateResource(hUpdateRes,
RT_STRING,
_T("KEY"),
MAKELANGID(LANG_NEUTRAL,SUBLANG_NEUTRAL),
str,
wcslen(str)*2);
EndUpdateResource(hUpdateRes,false);
well, I am not completely happy about that "wcslen(str)*2" to deterimine the needed size. Maybe anyone has a better idea about that.
for reading:
Code:
hExe = LoadLibrary(_T("c:\\Example_1.exe"));
hRes = FindResource(hExe, _T("KEY"), RT_STRING);
hResLoad = LoadResource(hExe, hRes);
lpResLock = (TCHAR*)LockResource(hResLoad);
Thanks a lot to all!
-
June 22nd, 2010, 07:59 AM
#7
Re: store a string in an executable
When you use the "T" macros for ansi/unicode compatability, you need to use them throughout. Use tclen() and sizeof(TCHAR):
Code:
result = UpdateResource(hUpdateRes,
RT_STRING,
_T("KEY"),
MAKELANGID(LANG_NEUTRAL,SUBLANG_NEUTRAL),
str,
tclen(str)*sizeof(TCHAR));
-
June 22nd, 2010, 10:55 AM
#8
Re: store a string in an executable
-
June 22nd, 2010, 07:39 PM
#9
Re: store a string in an executable
So now you can modify and read back resource strings. Great!
But how does it help you with checksum verification?
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio:
FeinWindows - replacement windows manager for Visual Studio, and more...
-
June 23rd, 2010, 02:36 AM
#10
Re: store a string in an executable
I still have to think about that algorithm to create that string to store in the exe and this algorithm must be secret. Checksum was only an example.
I have a COM-API to my application (not the tool to "sign") and I need a way to verify that the calls to API methods come from a "signed" executable. And only people with a specific license can use that signing tool.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|