Recursive task (resource enum+treeview+image_list) need help

Started by ramguru, December 28, 2005, 02:08:01 PM

Previous topic - Next topic

ramguru

Recently I've coded a recursive algo which enumerates resource types,names,languages everything at once. It worked OK so I've decided that the algo should fill treeview at the time it enumerates... It worked OK so I've decided that the algo should set image index of the level (2 for type, 2 for name, 2 for language) at the time it fills tree-view and enumerates res, but I couldn't find a working way...please help. The algo is really short...

; esi points to root   IMAGE_RESOURCE_DIRECTORY
; here ResDir      equ IMAGE_RESOURCE_DIRECTORY
; here ResDirEntry equ IMAGE_RESOURCE_DIRECTORY_ENTRY (w/o RECORD junk)
; I have 6 images in image_list with indexes 0..5
; I need to increase edi from 0..2 then from 1..2 and again from 1..2 and so on
;TYPE->NAME/ID->LANGUAGE ENUM oO|begin|Oo
push   13  ; KAPUT
push   0   ; root-child
push   esi ; root address
@A1:
pop    esi ; retrieve directory address
cmp    esi, 13 ; IS IT KAPUT ?
jz     @A3
pop    tvin.hParent ; retrieve child
xor    ecx, ecx
mov    cx, (ResDir ptr [esi]).NumberOfNamedEntries
add    cx, (ResDir ptr [esi]).NumberOfIdEntries ; number of entries in directory
add    esi, sizeof ResDir
@@:
cmp    ecx, 0
jz     @A1            ; go or not to go to new directory
;------- push what_can_be_corrupted
;...set tvin.item.pszText(..), tvin.item.iImage(edi shl 1), tvin.item.iSelectedImage((edi shl 1)+1)
invoke SendMessage, tree, TVM_INSERTITEM, 0, ADDR tvin
;  eax returns item's handle
;------- pop what_can_be_corrupted
mov    edx, (ResDirEntry ptr [esi]).DataEntry
add    esi, sizeof ResDirEntry
dec    ecx
test   edx, 80000000h ; is hi-bit set ?
jnz    @A2
jmp    @B
@A2:
xor    edx, 80000000h ; clear hi-bit
add    edx, ebx       ; offset + root
push   eax            ; if it's directory, save as parent
push   edx            ; save address for future visits
jmp    @B
@A3:
;TYPE->NAME/ID->LANGUAGE ENUM oO|end|Oo


Attachment contains complete code
BTW to create a smart recursive algo is like to win a good chess party...I really don't want it last more than week :)

[attachment deleted by admin]

ramguru

Finally I coped with this task, I guess I wasn't in my real shape. Attachment is updated with more attractive images and fully complete algo, but I would be gratefull if someone could make my algo shorter, any suggestions are welcome .... and HAPPY NEW YEAR to ALL reading this !

ramguru

Maybe someone has already done UpdateResource replacement in asm? As as far as my knowledge go I think that should involve recursion too, I have 7steps algo in my mind, but I think I'll have much more trouble with updating resource than with enumeration before. Any links or help would be very appreciative.

ramguru

I will continue custom (post here alone  :'( )... After numerous crashes & wayward desire of updated PE file not to be valid, finally I have some results. I've made a routine which updates only existing resource and does it pretty well even if new resource is bigger then old one (obviously I'm not using search & replace block algorithm).
P.S. Warning: if you're going to look at source-code, then you should take full responsibility of potential unrecoverable damage of your brain...

[attachment deleted by admin]

zooba

Quote from: ramguru on January 02, 2007, 09:29:53 PM
P.S. Warning: if you're going to look at source-code, then you should take full responsibility of potential unrecoverable damage of your brain...

You had me worried there. The code looks quite good, neat indenting (labels one indent back), consistent spacing, comment and whitespace separation. I've seen much worse looking code around here :U

asmrixstar

Dont wanna advertise but try A1format in the radasm section.
It may save you some time.

ramguru

Quote from: zooba on January 02, 2007, 10:20:15 PM
Quote from: ramguru on January 02, 2007, 09:29:53 PM
P.S. Warning: if you're going to look at source-code, then you should take full responsibility of potential unrecoverable damage of your brain...

You had me worried there. The code looks quite good, neat indenting (labels one indent back), consistent spacing, comment and whitespace separation. I've seen much worse looking code around here :U
Just looking at my code is not as harmful as trying to understand it :)

Quote from: asmrixstar on January 03, 2007, 07:09:56 AM
but try A1format
I'm actually not using RadASM for quite a while, but I've tried your adin.... it replaced "invoke" with "__" it was funny to play :)

Regarding my UpdateResource implementation, I'm going to make it add new resource not only replace existing...hard work is still ahead... :bg