flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > Non-x86 architectures > WinCE & ARM questions

Author
Thread Post new topic Reply to topic
ProMiNick



Joined: 24 Mar 2012
Posts: 142
Location: Russian Federation, Sochi

WinCE & ARM questions

revolution, can you explain this trickery:

Code:
          if $+8-_#function<4096
            ldr pc,[pc,_#function-$-8]
          else
            ldr r12,[pc]
            ldr pc,[r12]
            dw _#function
          end if


Am I right?: pc point not to instruction start like (e|r)ip in x86, but to second one instruction after next instruction.

why second part not so:

Code:
            ldr pc,[pc]
            nop
            dw _#function

It looks like 1 instruction shorter, but maybe I missed smthing and your variant is shortest possible?

And how you got coredll.inc it documented somewhere or you test this dll in wince, or extract it from *.BIN image?


Quote:
I drop this in first post if someone interests in emulator of arm & images for that emulator, & there are set of small programs for reverse engenering play too
https://drive.google.com/open?id=1Qe9oUFpOh_NhdM4r8i3jQoPOQXvCK4S0


_________________
I don`t like to refer by "you" to one person.
My soul requires acronim "thou" instead.


Last edited by ProMiNick on 18 May 2018, 19:15; edited 1 time in total
Post 15 May 2018, 13:07
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15727
Location: (514107) 2015 BZ509

Re: Questions to revolution


ProMiNick wrote:
revolution, can you explain this trickery:

Code:
          if $+8-_#function<4096
            ldr pc,[pc,_#function-$-8]
          else
            ldr r12,[pc]
            ldr pc,[r12]
            dw _#function
          end if


Am I right?: pc point not to instruction start like (e|r)ip in x86, but to second one instruction after next instruction.

In ARM mode the value of PC is the current instruction + 8. In Thumb mode it is a bit more complex. A single instruction can't access immediate memory offsets further than 4096 bytes away.

ProMiNick wrote:
why second part not so:

Code:
            ldr pc,[pc]
            nop
            dw _#function

It looks like 1 instruction shorter, but maybe I missed smthing and your variant is shortest possible?

It is a pointer to a pointer. The _#function value is not a pointer to the OS function, it is an intermediate pointer to the pointer to the OS function. The OS linker/loader will only link one pointer per function, we can't coax it to make new pointers each time we call a function. Since we can't reach the offset in one instruction, we have to make it a pointer to the pointer.

Another way to code it if you have the MOVW instruction available and the address is numerically higher but less than 2^16 bytes distant is this:

Code:
movw r12,_#function-$-12
ldr pc,[pc,r12]


ProMiNick wrote:
And how you got coredll.inc it documented somewhere or you test this dll in wince, or extract it from *.BIN image?

I have no documentation on coredll.dll. I reverse engineered the functions.

But, I wonder if there are any systems out there that still use WinCE? Maybe three people in the world use it now?
Post 15 May 2018, 13:47
View user's profile Send private message Visit poster's website Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 142
Location: Russian Federation, Sochi

one more...
Why apscall macros targeted for programs where programmer mix everithing within 1 PE section (sections are 4096 bytes aligned, and in many places maked macro branches that expects values distant from pc less than 4096 bytes)?
examples:
that simplification works only if we mix code & import within one section

Code:
if defined _#function & _#function-$-8<4096 & _#function-$-8>-4096
                mov lr,pc
                ldr pc,[pc,_#function-$-8]
        else
                bl function
        end if 

in common case:

Code:
bl function



or maybe it is ARM philosophy to mix everithig(code,data) relative in 4096 range, and than next portion.

lea is not ARM instruction it is macro? it hardcoded in IDE? or it defined anywhere?
Post 16 May 2018, 10:12
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15727
Location: (514107) 2015 BZ509


ProMiNick wrote:
Why apscall macros targeted for programs where programmer mix everithing within 1 PE section (sections are 4096 bytes aligned, and in many places maked macro branches that expects values distant from pc less than 4096 bytes)?

The idea is that the literal pool is placed close the the code where the values are needed. It you place it too far away (more than 4096 bytes) then the instructions for accessing it become much more complex. In ARM code this is normal. The caches are designed to operate with this functionality in mind.

"function"s with a leading underscore (_) are external to the code so they need a linking call "ldr pc, ..." and the pointer is placed into the literal pool by the macros. A local function without the underscore can be called with a simple "bl ...".

The 4096 constant is not the alignment, it is the restriction in the instruction encoding for LDR.

ProMiNick wrote:
lea is not ARM instruction it is macro? it hardcoded in IDE? or it defined anywhere?

In ARM speak it is ADR. It is synthesized by the assembler, and is documented in the ARM ARM.
Post 16 May 2018, 10:34
View user's profile Send private message Visit poster's website Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 142
Location: Russian Federation, Sochi

how to do this:

Code:
section '.text' code readable executable
apscall RegisterClass,wc

section '.nomatter' data readable executable 
; ensure that between "apscall RegisterClass,wc" & wc definition will be more than 4096 bytes
section '.data' data readable executable
        wc WNDCLASS 0,WindowProc,0,0,NULL,NULL,NULL,COLOR_BTNFACE+1,NULL,_class




there 2 variants:
use MOVEX instead of mov in PROCAPS.INC

Code:
                            if temp <> lastvalue
                                MOV lr,value
                            end if
                            lastvalue=temp
                            str lr,[sp,-tempcount*4-4]

and in

Code:
                        else if ~ r\#p eq value
                            MOV r\#p,value
                        end if \\} 



with smthing like

Code:
macro MOVEXT dest,src {
        local ..started
        ..started:
        if src and 0ff000000h
           mov dest,src and 0ff000000h ; shifts are resolved?
       end if
       if src and 0ff0000h
          if $-..started
            orr dest,dest,src and 0ff0000h
          else
            mov dest,src and 0ff0000h
          end if
       end if
       if src and 0ff00h
          if $-..started
            orr dest,dest,src and 0ff00h
          else
            mov dest,src and 0ff00h
          end if
       end if
       if src and 0ffh
          if $-..started
            orr dest,dest,src and 0ffh
          else
            mov dest,src and 0ffh
          end if
       end if




or add in block

Code:
    reverse
                local ..arg
                found equ no
                match i[like]za,:parameter: \{ found equ \}
                match =no:*ustring,found:parameter \{
                    def_ustring ..arg,ustring,0
                    found equ \}
                ;add here
                match =no:some=,more,found:parameter \{
                    def_astring ..arg,parameter,0
                    found equ \}
                match =no,found \{
                  if parameter eqtype ''
                    def_astring ..arg,parameter,0
                  end if \}
                tempcount=tempcount+1 



add this

Code:
match =no:=far data,found:parameter \{
                    def_fardata ..arg,parameter
                    found equ \}



and

Code:
macro def_fardata labl,data     {common align 4  ; is alignment needed?
labl dw data}



so after all code (syntax) is worked

Code:
section '.text' code readable executable
apscall RegisterClass,far wc
section '.data' data readable executable
        wc WNDCLASS 0,WindowProc,0,0,NULL,NULL,NULL,COLOR_BTNFACE+1,NULL,_class




previous one ever without needance in word far

Code:
                match =no,found \{
                  if parameter eqtype ''
                    def_astring ..arg,parameter,0
                  end if
                  if parameter shr 12 = $ shr 12 ; same section same page - referencing throw pc
                  else if parameter-$>200h | parameter-$<-200h ; if function located in 2 neibour pages - 512 bytes for function would be enough for referencing throw pc
                    def_fardata ..arg,parameter
                  else if
                  \} 



but

Code:
apscall CreateWindowEx,0,_class,_title,$10000000,0,0,100,100,NULL,NULL,[wc.hInstance],NULL
section '.data' data readable executable
        wc WNDCLASS 0,WindowProc,0,0,NULL,NULL,NULL,COLOR_BTNFACE+1,NULL,_class

still don`t

full code what I test is

Code:
format  PE GUI
entry   start

include 'WINCE.INC'

struct POINT
  x dw ?
  y dw ?
ends

struct WNDCLASS
  style         dw ?
  lpfnWndProc   dw ?
  cbClsExtra    dw ?
  cbWndExtra    dw ?
  hInstance     dw ?
  hIcon         dw ?
  hCursor       dw ?
  hbrBackground dw ?
  lpszMenuName  dw ?
  lpszClassName dw ?
ends

struct MSG
  hwnd    dw ?
  message dw ?
  wParam  dw ?
  lParam  dw ?
  time    dw ?
  pt      POINT
ends

NULL = 0
MB_ICONERROR=0    ; no matter for now
MB_OK=0           ; no matter for now
COLOR_BTNFACE=0   ; no matter for now
WM_DESTROY=$66


section '.text' code readable executable
  start:
        mov     r12,data.begin
        apscall GetModuleHandleW,0
        str     r0, [r12,wc.hInstance-data.begin]
        ;ldr     r12, [WindowProc]
        ;str     r12, [wc.lpfnWndProc]
        ;mov     r12, COLOR_BTNFACE+1
        ;str     r12, [wc.hbrBackground]
        ;ldr     r12, [_class]
        ;str     r12, [wc.lpszClassName]
        ;apscall LoadIconW,r0,IDI_APPLICATION;If I uncomment this
        ;str     r0, [r12,wc.hIcon-data.begin]; and uncomment this - next one error disapiared in compilation, but it makes exe compiled errorneusly it crashed near the call to CreateWindowExW
        apscall RegisterClassW,far wc
        cmp     r0,0
        beq     error
        apscall CreateWindowExW,0,_class,_title,$10000000,0,0,100,100,NULL,NULL,[wc.hInstance],NULL ; here I have error
        cmp     r0,0
        beq     error

  msg_loop:
        apscall GetMessageW,msg,NULL,0,0 ; {LDR R0, msg; MOV R1, NULL; MOV R2, #0; MOV R3, #0; BL GetMessage}
        cmp     r00
        beq     end_loop
        apscall TranslateMessage,msg ; {LDR R0, msg; BL TranslateMessage}
        apscall DispatchMessageW,msg ; {LDR R0, msg; BL DispatchMessage}
        b       msg_loop

  error
        apscall MessageBoxW,NULL,_error,NULL,MB_ICONERROR+MB_OK ; MOV R0, NULL; LDR R1, _error; MOV R2, NULL; MOV R3, MB_ICONERROR+MB_OK; BL MessageBox}

  end_loop
        apscall ExitThread,0

proc WindowProc nospil ,hwnd,wmsg,wparam,lparam
        cmp     r1,WM_DESTROY
        beq     .wmdestroy
  .defwndproc:
        apscall DefWindowProcW,R0,R1,R2,R3
        B       .finish
  .wmdestroy:
        apscall PostQuitMessage,0
        mov     r0,0
  .finish:
        ret
endp

section '.data' data readable executable
        data.begin:
        _class du 'FASMWINCE',0
        _title du 'WinCE program template',0
        _error du 'Startup failed.',0

        wc WNDCLASS 0,WindowProc,0,0,NULL,NULL,NULL,COLOR_BTNFACE+1,NULL,_class
        msg MSG

section '.idata' import data readable writeable

        library coredll,'COREDLL.DLL'
        include 'APICE\COREDLL.INC'

Post 16 May 2018, 13:56
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15727
Location: (514107) 2015 BZ509

IF you need the address of WindowProc then try with ADR, instead of LDR.

Also, you can't address wc directly. You will need to load the address into a register first (maybe with ADR also), then you can use "str r12,[r0,WNDCLASS.lpfnWndProc]", assuming r0 is the address of wc.
Post 16 May 2018, 14:08
View user's profile Send private message Visit poster's website Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 142
Location: Russian Federation, Sochi

patched PROCAPS.INC:

Code:
macro def_ustring labl,[string] {common labl dU string}
macro def_astring labl,[string] {common labl dB string

added

Code:
macro def_fardata labl,data     {common align 4  ; is alignment needed?
labl dw data


Code:

macro apscall function,[parameter] {
    common
        local pcount,tempcount,found,.skip,.size,param,last_value,temp,size,instr,i_s,msize
        virtual
                nop
                temp=$-$$
        end virtual
        if temp<>4
                halt ;APSCALL macro NOT usable in thumb mode
        end if
        if ~ parameter eq
                if .size
                    b .skip
                end if
                temp=$
                tempcount=0
    reverse
                local ..arg
                found equ no
                match i[like]za,:parameter: \{

added

Code:
                  if  like eqtype 0
                    if like shr 12 = $ shr 12 ; same section same page
                    else if like-$>200h | like-$<-200h
                      def_fardata ..arg,like
                    end if
                  end if


Code:
                found equ \}
                match =no:*ustring,found:parameter \{
                    def_ustring ..arg,ustring,0
                    found equ \}
                match =no:some=,more,found:parameter \{
                    def_astring ..arg,parameter,0
                    found equ \}
                match =no,found \{
                  if parameter eqtype ''
                    def_astring ..arg,parameter,0
                  end if

added

Code:
                  if  parameter eqtype 0
                    if parameter shr 12 = $ shr 12 ; same section same page
                    else if parameter-$>200h | parameter-$<-200h
                      def_fardata ..arg,parameter
                    end if
                  end if


Code:
                  \}
                tempcount=tempcount+1
    common
                pcount=tempcount
                align 4
                .size=$-temp
                if .size
                    .skip:
                end if
                lastvalue=1 shl 63
                tempcount=0
    reverse
                if tempcount<(pcount-4)
                    found equ no
                    define param parameter
                    match [address],parameter \{

added

Code:
                        if defined ..arg
                          ADD lr,pc,..arg-$-8
                          LDR lr,[lr]
                        else 


Code:
                          LDR lr,[address]

added

Code:
                        end if


all rest remain untouched

compiled successfuly, but


Description:
Filesize: 184.05 KB
Viewed: 170 Time(s)

wince.jpg



_________________
I don`t like to refer by "you" to one person.
My soul requires acronim "thou" instead.
Post 16 May 2018, 14:48
View user's profile Send private message Send e-mail Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 142
Location: Russian Federation, Sochi

I canceled from avoiding word far in PROCAPS.
word far precedes values that used from other PE sections and therefore needed in special handling.


Code:
format  PE GUI
entry   start

include 'WINCE.INC'

struct POINT
  x dw ?
  y dw ?
ends

struct WNDCLASS
  style         dw ?
  lpfnWndProc   dw ?
  cbClsExtra    dw ?
  cbWndExtra    dw ?
  hInstance     dw ?
  hIcon         dw ?
  hCursor       dw ?
  hbrBackground dw ?
  lpszMenuName  dw ?
  lpszClassName dw ?
ends

struct MSG
  hwnd    dw ?
  message dw ?
  wParam  dw ?
  lParam  dw ?
  time    dw ?
  pt      POINT
ends

NULL = 0
MB_ICONERROR=0    ; no matter for now
MB_OK=0           ; no matter for now
COLOR_BTNFACE=0   ; no matter for now
WM_DESTROY=$66

section '.text' code readable executable
  start:
        mov     r12,data.begin
        apscall GetModuleHandleW,0
        str     r0, [r12,wc.hInstance-data.begin]
        apscall RegisterClassW,far wc
        cmp     r0,0
        beq     error ; on call CreateWindowExW emulated WinCE OS freezes, if change beq with b then showed message "Startup failed." and program normaly closed
        apscall CreateWindowExW,0,far _class,far _title,$10000000,0,0,100,100,NULL,NULL,[wc.hInstance],NULL ; here I have error
        cmp     r0,0
        beq     error

  msg_loop:
        apscall GetMessageW,far msg,NULL,0,0 ; {LDR R0, msg; MOV R1, NULL; MOV R2, #0; MOV R3, #0; BL GetMessage}
        cmp     r00
        beq     end_loop
        apscall TranslateMessage,far msg ; {LDR R0, msg; BL TranslateMessage}
        apscall DispatchMessageW,far msg ; {LDR R0, msg; BL DispatchMessage}
        b       msg_loop

  error
        apscall MessageBoxW,NULL,far _error,NULL,MB_ICONERROR+MB_OK ; MOV R0, NULL; LDR R1, _error; MOV R2, NULL; MOV R3, MB_ICONERROR+MB_OK; BL MessageBox}

  end_loop
        apscall ExitThread,0

proc WindowProc nospil ,hwnd,wmsg,wparam,lparam
        cmp     r1,WM_DESTROY
        beq     .wmdestroy
  .defwndproc:
        apscall DefWindowProcW,R0,R1,R2,R3
        B       .finish
  .wmdestroy:
        apscall PostQuitMessage,0
        mov     r0,0
  .finish:
        ret
endp

section '.skip' data readable writeable 
        dd 0

section '.data' data readable writeable ; accidentaly previously section has executable flag instead of writeable
        data.begin:
        _class du 'FASMWINCE',0
        _title du 'WinCE program template',0
        _error du 'Startup failed.',0
        align 4 ; when wc was misaligned program was crashed in "str     r0, [r12,wc.hInstance-data.begin]"
        wc WNDCLASS 0,WindowProc,0,0,NULL,NULL,NULL,COLOR_BTNFACE+1,NULL,_class
        msg MSG

section '.idata' import data readable writeable

        library coredll,'COREDLL.DLL'
        include 'APICE\COREDLL.INC'



Any ideas what is wrong in CreateWindowExW or in WindowProc processing?


Description:
Download
Filename: PROCAPS.INC
Filesize: 20.44 KB
Downloaded: 4 Time(s)


_________________
I don`t like to refer by "you" to one person.
My soul requires acronim "thou" instead.
Post 17 May 2018, 23:48
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15727
Location: (514107) 2015 BZ509

Can you attach a full set of sources for the code you assembled?. I'll see what I can find.
Post 18 May 2018, 06:56
View user's profile Send private message Visit poster's website Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 142
Location: Russian Federation, Sochi

program donor for ideas attached
7kb in size (in wince HLL wrapper around main is perfect - it has many lines of code that actualy does nothing!)


Description: I already cleared in it all hll shit around of start - so it is still normal work. & listing inside
Download
Filename: Utilities.zip
Filesize: 30.35 KB
Downloaded: 4 Time(s)

Description: my fasmarm with corrections in procaps
Download
Filename: FASMARM.zip
Filesize: 736.26 KB
Downloaded: 3 Time(s)


_________________
I don`t like to refer by "you" to one person.
My soul requires acronim "thou" instead.
Post 18 May 2018, 10:17
View user's profile Send private message Send e-mail Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 142
Location: Russian Federation, Sochi

I patched winmain(start) in donor file so it will have more suitable form for making macros over it

Code:
start                                   ; DATA XREF: HEADER:00010100o                                                                                                                                                
                                        ; HEADER:00010104o ...                                                                                                                                                       
                                                                                                                                                                                                                      
X               = -0x78                                                                                                                                                                                               
Y               = -0x74                                                                                                                                                                                               
nWidth          = -0x70                                                                                                                                                                                               
nHeight         = -0x6C                                                                                                                                                                                               
hWndParent      = -0x68                                                                                                                                                                                               
hMenu           = -0x64                                                                                                                                                                                               
hInstance       = -0x60                                                                                                                                                                                               
lpParam         = -0x5C                                                                                                                                                                                               
Msg             = -0x50                                                                                                                                                                                               
WndClass        = -0x30                                                                                                                                                                                               
                                                                                                                                                                                                                      
                STMFD           SP!, {R0,LR}                                                                                                                                                                          
                SUB             SPSP, #0x70                                                                                                                                                                         
                STR             R0, [SP,#0x78+WndClass.hInstance]                                                                                                                                                     
                LDR             R6, =dword_131F0                                                                                                                                                                 
                STR             R0, [R6]                                                                                                                                                                              
                MOV             R5R0                                                                                                                                                                                
                ANDEQ           R0R0R0 ;smthing as nop only placeholder code is shrinked after optimizing
                ANDEQ           R0R0R0 ;smthing as nop
                ANDEQ           R0R0R0 ;smthing as nop
                ANDEQ           R0R0R0 ;smthing as nop
                ANDEQ           R0R0R0 ;smthing as nop
                ANDEQ           R0R0R0 ;smthing as nop
                ANDEQ           R0R0R0 ;smthing as nop
                ANDEQ           R0R0R0 ;smthing as nop
                ANDEQ           R0R0R0 ;smthing as nop
                ANDEQ           R0R0R0 ;smthing as nop
                ANDEQ           R0R0R0 ;smthing as nop
                ANDEQ           R0R0R0 ;smthing as nop
                MOV             R0, #0  ; int                                                                                                                                                                         
                STR             R0, [SP,#0x78+WndClass.cbClsExtra]                                                                                                                                                    
                STR             R0, [SP,#0x78+WndClass.cbWndExtra]                                                                                                                                                    
                STR             R0, [SP,#0x78+WndClass.hCursor]                                                                                                                                                       
                STR             R0, [SP,#0x78+WndClass.lpszMenuName]                                                                                                                                                  
                BL              GetStockObject                                                                                                                                                                        
                STR             R0, [SP,#0x78+WndClass.hbrBackground]                                                                                                                                                 
                LDR             R1, =aIdi_icon1 ; "IDI_ICON1"                                                                                                                                                         
                MOV             R0, #0  ; hInstance                                                                                                                                                                   
                BL              LoadIconW                                                                                                                                                                             
                STR             R0, [SP,#0x78+WndClass.hIcon]                                                                                                                                                         
                MOV             R0, #1                                                                                                                                                                                
                STR             R0, [SP,#0x78+WndClass]                                                                                                                                                               
                LDR             R0, =sub_111A0                                                                                                                                                                        
                STR             R0, [SP,#0x78+WndClass.lpfnWndProc]                                                                                                                                                   
                LDR             R7, =aYusu ; "Yusu"                                                                                                                                                                   
                STR             R7, [SP,#0x78+WndClass.lpszClassName]                                                                                                                                                 
                ADD             R0SP, #0x78+WndClass ; lpWndClass                                                                                                                                                   
                BL              RegisterClassW                                                                                                                                                                        
                MOV             R1R0,LSL#16                                                                                                                                                                         
                MOVS            R0R1,LSR#16                                                                                                                                                                         
                ADDEQ           SPSP, #0x70                                                                                                                                                                         
                LDMEQFD         SP!, {R0,PC}                                                                                                                                                                          
                MOV             R0, #0  ; nIndex                                                                                                                                                                      
                BL              GetSystemMetrics                                                                                                                                                                      
                LDR             R1, =dword_131E0                                                                                                                                                                      
                STR             R0, [R1]                                                                                                                                                                              
                STR             R0, [SP,#0x78+nWidth; nWidth  ;maybe for macro value should be saved in r6 that free for use here
                MOV             R0, #1  ; nIndex                                                                                                                                                                      
                BL              GetSystemMetrics                                                                                                                                                                      
                LDR             R1, =dword_131E4                                                                                                                                                                      
                STR             R0, [R1]                                                                                                                                                                              
                STR             R0, [SP,#0x78+nHeight; nHeight ;maybe for macro value should be saved in r8 that free for use here
                MOV             R0, #0  ; dwExStyle  ; this line would precede apscall macro
                STR             R0, [SP,#0x78+lpParam; lpParam                                                                                                                                                      
                STR             R5, [SP,#0x78+hInstance; hInstance                                                                                                                                                  
                STR             R0, [SP,#0x78+hMenu; hMenu                                                                                                                                                          
                STR             R0, [SP,#0x78+hWndParent; hWndParent                                                                                                                                                
                STR             R0, [SP,#0x78+Y; Y                                                                                                                                                                  
                STR             R0, [SP,#0x78+X; X                                                                                                                                                                  
                MOV             R3, #0x10000000 ; dwStyle                                                                                                                                                             
                LDR             R2, =aSysneitfSearch ; "Sysneitf Search"                                                                                                                                              
                MOV             R1R7  ; lpClassName                                                                                                                                                                 
                BL              CreateWindowExW ;r0,r7,far aSysneitfSearch,$10000000,r0,r0,r6,r8,r0,r0,r5,r0
                MOVS            R4R0                                                                                                                                                                                
                MOVEQ           R0, #0                                                                                                                                                                                
                ADDEQ           SPSP, #0x70                                                                                                                                                                         
                LDMEQFD         SP!, {R0,PC}                                                                                                                                                                          
                LDR             R1, =aAccelerator1 ; "Accelerator1"                                                                                                                                                   
                MOV             R0R5  ; hInstance                                                                                                                                                                   
                BL              LoadAcceleratorsW                                                                                                                                                                     
                MOV             R8R0                                                                                                                                                                                
                MOV             R1R9  ; nCmdShow                                                                                                                                                                    
                MOV             R0R4  ; hwnd                                                                                                                                                                        
                BL              ShowWindow                                                                                                                                                                            
                MOV             R0R4  ; hwnd                                                                                                                                                                        
                BL              UpdateWindow                                                                                                                                                                          
                                                                                                                                                                                                                      
loc_1112C                               ; CODE XREF: start+15Cj                                                                                                                                                      
                                        ; start+170j                                                                                                                                                                 
                MOV             R3, #0  ; wMsgFilterMax                                                                                                                                                               
                MOV             R2, #0  ; wMsgFilterMin                                                                                                                                                               
                MOV             R1, #0  ; hWnd                                                                                                                                                                        
                ADD             R0SP, #0x78+Msg ; lpMsg                                                                                                                                                             
                BL              GetMessageW                                                                                                                                                                           
                CMP             R0, #0                                                                                                                                                                                
                BEQ             loc_11174                                                                                                                                                                             
                ADD             R2SP, #0x78+Msg ; lpMsg                                                                                                                                                             
                MOV             R1R8  ; hAccTable                                                                                                                                                                   
                MOV             R0R4  ; hWnd                                                                                                                                                                        
                BL              TranslateAcceleratorW                                                                                                                                                                 
                CMP             R0, #0                                                                                                                                                                                
                BNE             loc_1112C                                                                                                                                                                             
                ADD             R0SP, #0x78+Msg ; pMsg                                                                                                                                                              
                BL              TranslateMessage                                                                                                                                                                      
                ADD             R0SP, #0x78+Msg ; lpMsg                                                                                                                                                             
                BL              DispatchMessageW                                                                                                                                                                      
                B               loc_1112C                                                                                                                                                                             
; ---------------------------------------------------------------------------                                                                                                                                         
                                                                                                                                                                                                                      
loc_11174                               ; CODE XREF: start+144j                                                                                                                                                      
                LDR             R0, [SP,#0x78+Msg.wParam]                                                                                                                                                             
                ADD             SPSP, #0x70                                                                                                                                                                         
                LDMFD           SP!, {R0,PC}                                                                                                                                                                          
; End of function start 


of course after patch exe still works normally

once again trying to make app (not task) in WinCE:

Code:
        format  PE GUI
        entry   start
        include 'WINCE.INC'

struct POINT
  x dw ?
  y dw ?
ends

struct WNDCLASS
  style         dw ?
  lpfnWndProc   dw ?
  cbClsExtra    dw ?
  cbWndExtra    dw ?
  hInstance     dw ?
  hIcon         dw ?
  hCursor       dw ?
  hbrBackground dw ?
  lpszMenuName  dw ?
  lpszClassName dw ?
ends

struct MSG
  hwnd    dw ?
  message dw ?
  wParam  dw ?
  lParam  dw ?
  time    dw ?
  pt      POINT
ends

section '.text' code readable executable

start:
virtual at sp
  x          dw ?
  y          dw ?
  nWidth     dw ?
  nHeight    dw ?
  hWndParent dw ?
  hMenu      dw ?
  hInstance  dw ?
  lpParam    dw ?
  Msg        MSG
  WndClass   WNDCLASS
end virtual
        stmfd   sp!, {r0,lr}
        sub     spsp$70
        str     r0, [WndClass.hInstance]
        ;ldr     r6, [pc+..off_11198-$-8] ;ldr     r6, =dword_131F0
        ;str     r0, [r6]
        mov     r5r0
        mov     r00
        str     r0, [WndClass.cbClsExtra]
        str     r0, [WndClass.cbWndExtra]
        str     r0, [WndClass.hCursor]
        str     r0, [WndClass.lpszMenuName]
        ;apscall LoadIconW,0,[..off_1119C]
        str     r0, [WndClass.hIcon]
        apscall GetStockObject,r0
        str     r0, [WndClass.hbrBackground]
        mov     r0, #1
        str     r0, [WndClass]
        ldr     r0, [pc+..off_11194-$-8;ldr     r0, =sub_111A0
        str     r0, [WndClass.lpfnWndProc]
        ldr     r7, [pc+..off_11190-$-8;ldr     r7, =_class
        str     r7, [WndClass.lpszClassName]
        apscall RegisterClassWaddr WndClass
        mov     r1r0,lsl 16
        movs    r0r1,LSR 16
        addeq   spsp$70
        ldmeqfd sp!, {r0,pc}
        apscall GetSystemMetrics,0
        ;ldr     r1, [pc+..off_11188-$-8] ;ldr     r1, =dword_131E0
        ;str     r0, [r1]
        mov     r6r0 ;str     r0, [nWidth]
        apscall GetSystemMetrics,1
        ;ldr     r1, [pc+..off_11184-$-8] ;ldr     r1, =dword_131E0
        ;str     r0, [r1]
        mov     r8r0 ;str     r0, [nWidth]
        mov     r00
        apscall CreateWindowExW,r0,r7,[..off_11180],$10000000,r0,r0,r6,r8,r0,r0,r5,r0
        movs    r4r0
        addeq   spsp$70
        ldmeqfd sp!, {r0,pc}
        ;apscall LoadAcceleratorsW,r5,[..off_1118C]
        ;mov     r8, r0
        apscall MessageBoxW,0,addr Text,addr Caption,0+0
        apscall ExitThread,0
        mov     r8r0
        apscall ShowWindow,r4,r9
        apscall UpdateWindow,r4

  msg_loop:

        apscall GetMessageW,addr Msg,0,0,0
        cmp     r00
        beq     end_loop
        ;apscall TranslateAcceleratorW,r4,r8,0,0
        ;cmp     r0, 0
        ;bne     msg_loop
        apscall TranslateMessage,addr Msg
        apscall DispatchMessageW,addr Msg
        b       msg_loop
  end_loop:
        ldr     r0, [Msg.wParam]
        add     spsp$70
        ldmfd sp!, {r0,pc}

..off_11180 dw    _title
;..off_11184 dw    dword_131E4
;..off_11188 dw    dword_131E0
..off_1118C dw    aAccelerator1
..off_11190 dw    _class
..off_11194 dw    WndProc ;WndProc
;..off_11198 dw    dword_131F0
..off_1119C dw    aIdi_icon1

WndProc:
        stmfd   sp!, {r4-r8,r11,lr}
        mov     r5,r0
        mov     r7,r2
        mov     r8,r3
        cmp     r1,2
        beq     .wmdestroy
        apscall DefWindowProcW,r0,r1,r2,r3
        ldmfd   sp!, {r4-r8,r11,PC}
  .wmdestroy:
        apscall PostQuitMessage,0
        mov     r0,0
        ldmfd   sp!, {r4-r8,r11,PC}

section '.data' data readable writeable
  _class du 'Yusu',0
  _title du 'WinCE example app',0
  ;aIdi_icon1 du 'IDI_ICON1',0
  ;aAccelerator1 du 'Accelerator1',0
  ;dword_131E0 dw ?
  ;dword_131E4 dw ?
  ;dword_131F0 dw ?

section '.idata' import readable writeable

        library coredll,'COREDLL.DLL'
        include 'APICE\COREDLL.INC'  

problem apscall dos`n operate with locals defined via virtual not throw local. How make proc wrapper that makes exatctly that "STMFD SP!, {R0,LR};SUB SP, SP, #0x70"?


Description:
Download
Filename: search3.zip
Filesize: 2.38 KB
Downloaded: 0 Time(s)


_________________
I don`t like to refer by "you" to one person.
My soul requires acronim "thou" instead.
Post 23 May 2018, 10:39
View user's profile Send private message Send e-mail Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >

Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2018, Tomasz Grysztar.
Powered by rwasa.