News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

EnumResourceNames

Started by georgek01, March 27, 2008, 08:56:47 AM

Previous topic - Next topic

georgek01

I'm trying to enumerate all RT_STRING types in the application resource, but get Invalid access to memory location.

There are 3 entries in the STRINGTABLE. Even if I use the message box to display the application name instead of the lpszName parameter, only one message box is displayed, whereas there should be 3 - one for each resource entry.

Any idea perhaps why the error occurs?

[attachment deleted by admin]
What we have to learn to do, we learn by doing.

- ARISTOTLE (384-322 BC)

Adamanteus

 But resource is the STRINGTABLE and it's one and only could be one, if to enumerate RT_DIALOG, the dialog elements not counting.

ramguru

your project works fine:

EnumResProc proc hModule:DWORD, lpType:DWORD, lpName:DWORD, lParam:DWORD
LOCAL buf[32]:BYTE

invoke dwtoa, lpName, ADDR buf
invoke MessageBox,0,ADDR buf,addr szAppName,MB_OK  ; --> 126

mov eax,TRUE
ret
EnumResProc endp


You have to check if resource_name is integer or string...in this case it was integer :)

georgek01

Thank you for the assistance!  :U
What we have to learn to do, we learn by doing.

- ARISTOTLE (384-322 BC)

xandaz

   Hi there. I'm having some trouble also ResourceEnum... What can i use to get the handle outa resource file that isn't mapped into the address space of the calling process? I tried loadlibrary but doesn't work.
   ty and bye

ecube

"Yes, finally i got the grip of the structure of a string table :

it is basically a block of memory.
strings are following one another, they are not null terminated, and each string begins with a number that specifies its size.

strings are stored in Unicode format and each letter takes 2 bytes of memory

FindResource will return a pointer to a block of 16 strings, and the parameter that has to be passed to FindResource must contain the number of that block. For example, the sixth block of 16 strings (like in my case) will have strings with IDs 0x60 to 0x6F (or 96 to 111). A simple way to produce that number to pass to FindResource as the name of the resource, is to divide the string ID by 16 and add 1, or right shift the string ID by 4 and add 1. That's all. I use a while loop to parse the block of memory that contains the string that i am interested in, until i find that string."


CHString szwstr;

//get the offset of the the block within the string table
DWORD nID = (lpText >> 4) + 1;

//get the offset of the item within the block
DWORD nitemID = lpText % 0x10;

//get handle to the beginning of the block of 16 strings, where each string begins with its size
HRSRC hRes = FindResourceEx(hInst, RT_STRING,
MAKEINTRESOURCE(nID), hLang);
if (hRes)
{
HGLOBAL hGlo = LoadResource(hInst, hRes);
LPCWSTR lpStr = (LPCWSTR)LockResource(hGlo);
int i = 0, nStr = 0;
DWORD dwsize = SizeofResource(hInst, hRes);
while(i < dwsize)
{
if (nStr == nitemID)
{
if (lpStr[i] != 0x0000)
szwstr = CHString(&lpStr[i+1], lpStr[i]);
else
szwstr = L"";
break;
}
if (lpStr[i] != 0x0000)
i += lpStr[i]+1;
else
i++;
nStr++;
}
}


xandaz

    hi there. i checked out the resource.zip example cause i'm interested in this formatmessage thing. I looked around msn and other sites but i coun't find what %i stands for? And %s? i saw its a system string and %i are error codes but i couldn't get documentation on that. Someone feel free to reply unless you feel its off topic for this thread ( which it is ).
   Thanks and bye
    best regards from X

jj2007

%i and %s are formatting codes being used with printf. If you want FormatMessage, try this snippet. ErrBuf$ must be

ShowWinErr proc
  pushad
invoke GetLastError
invoke FormatMessage,FORMAT_MESSAGE_FROM_SYSTEM,
0, ; GetItFromSystem
eax, ; ErrNum
0, ; Default language
ErrBuf$, ; where to send the string from system
400, 0          ; size 400, no arguments
.if ShowFormatted!=1
invoke lstrcat, ErrBuf$, ShowFormatted
.endif
MsgBox 0, ErrBuf$, "error", MB_OK
popad
ret
ShowWinErr endp