Hi,

I have been trying to read resources using the structs like IMAGE_RESOURCE_ENTRY etc. However I got stuck at one part, and was hoping that the forumers would be able to help me ;)



ExtractResources proc uses edi ecx ebx edx esi
mov edi, pMapping
assume edi:PTR IMAGE_DOS_HEADER
add edi,[edi].e_lfanew
assume edi:PTR IMAGE_NT_HEADERS
mov eax,[edi].OptionalHeader.DataDirectory[SIZEOF IMAGE_DATA_DIRECTORY * 2].VirtualAddress
cmp eax,0
jnz Resource
NoResource:
invoke MessageBox,0, ADDR NoRes, ADDR Error, MB_OK
ret
Resource:
invoke RVAToOffset,pMapping,eax
add eax,pMapping
mov edi,eax
assume edi:PTR IMAGE_RESOURCE_DIRECTORY
mov cx, [edi].NumberOfIdEntries
movzx ecx,cx
mov IDEntries,ecx
mov bx,[edi].NumberOfNamedEntries
movzx ebx,bx
add ecx,ebx ;Total number of Resource_directory
add edi,SIZEOF IMAGE_RESOURCE_DIRECTORY
assume edi:PTR IMAGE_RESOURCE_DIRECTORY_ENTRY
mainloop:
push ecx
mov tvs.hParent,TVI_ROOT
cmp DWORD PTR[edi],1
je cursor
cmp DWORD PTR[edi],2
je bitmap
cmp DWORD PTR[edi],3
je icon
cmp DWORD PTR[edi],4
je menu
cmp DWORD PTR[edi],5
je dialog
cmp DWORD PTR[edi],6
je stringtable
cmp DWORD PTR[edi],11
je messagetable
cmp DWORD PTR[edi],12
je groupcursor
cmp DWORD PTR[edi],14
je groupicon
cmp DWORD PTR[edi],16
je versioninfo
jmp mainloopcontinue
cursor:
mov tvs.item.pszText, OFFSET szcursor
invoke SendMessage,hTreeView,TVM_INSERTITEM,0,ADDR tvs
mov hTree,eax
lea edx,[edi+eax+0ch] ;OffsetToData
and edx,0000ffffh
xor ebx,ebx
xor ecx,ecx
mov cx,WORD PTR[edi+edx] ;NamedEntries <----the value i get here is incorrect. It is too large
cursorloop1:
test ecx,ecx
jz cursorloop2
lea eax,[edi+edx+4] ;Address of Resource name
;same as adding SIZEOF resource directory entry, just that to preserve register values
push ecx
mov ecx,ebx
shl ecx,3
add eax,ecx ;eax = Position of pointer in the resource directory entry
pop ecx
push WORD PTR[eax]
int 3
add eax,2
push eax
lea eax,buffer
push eax
call lstrcpyn
invoke MessageBox,0,ADDR buffer,0,0
inc ebx
dec ecx
jnz cursorloop1
mov cx,WORD PTR[edi+edx+2] ;ID Entries
movzx ecx,cx
cursorloop2:
jmp mainloopcontinue
bitmap:
mov tvs.item.pszText, OFFSET szbitmap
invoke SendMessage,hTreeView,TVM_INSERTITEM,0,ADDR tvs
mov [hTree+4],eax
jmp mainloopcontinue
icon:
mov tvs.item.pszText, OFFSET szicon
invoke SendMessage,hTreeView,TVM_INSERTITEM,0,ADDR tvs
mov [hTree+8],eax
jmp mainloopcontinue
menu:
mov tvs.item.pszText, OFFSET szmenu
invoke SendMessage,hTreeView,TVM_INSERTITEM,0,ADDR tvs
mov [hTree+12],eax
jmp mainloopcontinue
dialog:
mov tvs.item.pszText, OFFSET szdialog
invoke SendMessage,hTreeView,TVM_INSERTITEM,0,ADDR tvs
mov [hTree+16],0
jmp mainloopcontinue
stringtable:
mov tvs.item.pszText, OFFSET szstringtable
invoke SendMessage,hTreeView,TVM_INSERTITEM,0,ADDR tvs
mov [hTree+20],0
jmp mainloopcontinue
messagetable:
mov tvs.item.pszText, OFFSET szmessagetable
invoke SendMessage,hTreeView,TVM_INSERTITEM,0,ADDR tvs
mov [hTree+24],0
jmp mainloopcontinue
groupcursor:
mov tvs.item.pszText, OFFSET szgroupcursor
invoke SendMessage,hTreeView,TVM_INSERTITEM,0,ADDR tvs
mov [hTree+28],0
jmp mainloopcontinue
groupicon:
mov tvs.item.pszText, OFFSET szgroupicon
invoke SendMessage,hTreeView,TVM_INSERTITEM,0,ADDR tvs
mov [hTree+32],0
jmp mainloopcontinue
versioninfo:
mov tvs.item.pszText, OFFSET szversioninfo
invoke SendMessage,hTreeView,TVM_INSERTITEM,0,ADDR tvs
mov [hTree+36],0
jmp mainloopcontinue
mainloopcontinue:
add edi, SIZEOF IMAGE_RESOURCE_DIRECTORY_ENTRY
pop ecx
dec ecx
jnz mainloop
ret
ExtractResources endp
Posted on 2002-10-11 06:48:19 by roticv
lea edx, ;OffsetToData
and edx,0000ffffh
xor ebx,ebx
xor ecx,ecx
mov cx,WORD PTR ;NamedEntries <----the value i get here is incorrect. It is too large
this looks not bad, didn't you mix up <lea edx, > and <mov edx, >?
Posted on 2002-10-15 12:55:20 by beaster
Yeah... i did mess it up there, i fixed that part. However i got stuck in another part.. haix.. this is so complicated.
Posted on 2002-10-16 01:41:37 by roticv