flat assembler
Message board for the users of flat assembler.

Index > Windows > Read File and Output to display win7

Author
Thread Post new topic Reply to topic
aasom65



Joined: 31 Oct 2014
Posts: 4
aasom65
In this example not work loading file.Please help me
Code:
format PE GUI 5.0

include 'win32wx.inc'



width  = 1280
height = 1024

.code
start:                         ;Òóò ìîæíî ðèñîâàòü
invoke  OpenFile , picture , FilePE


invoke  ReadFile , Raster1 ,2,0
invoke  CloseHandle,picture
invoke  MessageBox,0,Raster1,0,MB_OK ;âûâîäèì ñîîáùåíèå

    


;mov  esi,Raster           ;ïåðåìåííàÿ Raster ñîäåðæèò èôîðìàöèþ î öâåòå ïèêñåëåé
;add  esi,width*4
;mov  dword[esi-4],255
;mov  ecx,(width-1)*height
;@@:lodsd
   ;xor eax,[esi-width*4]

   
;   mov [esi],eax
;loop @b
;;;;;;;;;;;;;;;;;;;
 
;@@:invoke GetDC,0                                                          ;Ïîëó÷àåì Device Context ðàáî÷åãî ñòîëà
 ;  invoke SetDIBitsToDevice,eax,0,0,width,height,0,0,0,height,Raster,bmi,0 ;Êîïèðóåì èçîáðàæåíèå èç ïåðåìåííîé Raster íà ýêðàí
;   invoke GetAsyncKeyState,VK_ESCAPE                                       ;Ïðîâåðÿåì ñîñòîÿíèå êëàâèøè ESCAPE
;   test   eax,eax                                                          ;Åñëè íå íàæàòà
;jz @b                                                                     ;Ïåðåõîäèì íà ìåòêó @@
 
invoke ExitProcess,0       ;Âûõîä èç ïðîãðàììû
 
.data
FilePE          db 'r',0
Raster  rd width*height
picture db '111.txt',0
bmi     BITMAPINFOHEADER sizeof.BITMAPINFOHEADER,width,-height,1,24,0,width*height*3
mestitle db 'C',0 ;ïåðåìåííàÿ ñ çàãîëîâêîì
Raster1  db 'C',0
.end start      
Post 31 Oct 2014, 16:15
View user's profile Send private message Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1419
Location: Toronto, Canada
AsmGuru62
Try this (just replace the file name with yours):
Code:
.code
start:
    ;
    ; Open file and save its handle into EBX
    ;
    invoke    CreateFileA, achFileName, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, 0
    mov       ebx, eax
    ;
    ; If file is not opened - get out!
    ;
    cmp       eax, INVALID_HANDLE_VALUE
    je        .quit
    ;
    ; ESI = file size in bytes
    ;
    invoke    GetFileSize, ebx, 0
    mov       esi, eax
    mov       [dwFileSize], eax
    ;
    ; Allocate memory for the file contents
    ; EDI = pointer to that buffer
    ;
    invoke    VirtualAlloc, 0, esi, MEM_RESERVE or MEM_COMMIT, PAGE_READWRITE
    mov       edi, eax
    mov       [pFileBytes], eax
    ;
    ; If allocation fails - close file and get out!
    ;
    test      eax, eax
    jz        .close_file
    ;
    ; Read the file into buffer and then close file.
    ;
    invoke    ReadFile, ebx, edi, [dwFileSize], dwNumLoaded, 0
    invoke    CloseHandle, ebx
    ;
    ; Now the file is fully loaded at the address in EDI... do whatever...
    ;
    nop
    nop
    nop
    nop
    nop
    ;
    ; Release memory and quit
    ;
    invoke    VirtualFree, [pFileBytes], 0, MEM_RELEASE
    jmp       .quit

.close_file:
    invoke    CloseHandle, ebx

.quit:
    invoke    ExitProcess, 0

.data
    pFileBytes   dd 0
    dwFileSize   dd 0
    dwNumLoaded  dd 0
    achFileName  db 'C:\Users\Public\Pictures\Sample Pictures\Desert.Jpg',0
    
Post 31 Oct 2014, 18:08
View user's profile Send private message Send e-mail Reply with quote
aasom65



Joined: 31 Oct 2014
Posts: 4
aasom65
I'm integrated with my program but file don't read, and I don't understand adress of load file is my Raster1?
Code:
format PE GUI 5.0

include 'win32wx.inc'

width  = 1280
height = 1024

.code
start:                         ;Òóò ìîæíî ðèñîâàòü

    ; Open file and save its handle into EBX 
    ; 
    invoke    CreateFileA, achFileName, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, 0 
    mov       ebx, eax 
    ; 
    ; If file is not opened - get out! 
    ; 
    cmp       eax, INVALID_HANDLE_VALUE 
    je        .quit 
    ; 
    ; ESI = file size in bytes 
    ; 
    invoke    GetFileSize, ebx, 0 
    mov       esi, eax 
    mov       [dwFileSize], eax 
    ; 
    ; Allocate memory for the file contents 
    ; EDI = pointer to that buffer 
    ; 
    invoke    VirtualAlloc, 0, esi, MEM_RESERVE or MEM_COMMIT, PAGE_READWRITE 
    mov       edi, eax 
    mov       [pFileBytes], eax 
    ; 
    ; If allocation fails - close file and get out! 
    ; 
    test      eax, eax 
    jz        .close_file 
    ; 
    ; Read the file into buffer and then close file. 

    invoke    ReadFile, ebx, Raster1, [dwFileSize], dwNumLoaded, 0
    invoke    CloseHandle, ebx 
    ; 
    ; Now the file is fully loaded at the address in EDI... do whatever... 
    ; 
    nop 
    nop 
    nop 
    nop 
    nop 
    ; 
    ; Release memory and quit 
    ; 
    invoke    VirtualFree, [pFileBytes], 0, MEM_RELEASE 


.close_file: 
    invoke    CloseHandle, ebx 



invoke  MessageBox,0,Raster1,0,MB_OK ;âûâîäèì ñîîáùåíèå


;mov  esi,Raster           ;ïåðåìåííàÿ Raster ñîäåðæèò èôîðìàöèþ î öâåòå ïèêñåëåé
;add  esi,width*4
;mov  dword[esi-4],255
;mov  ecx,(width-1)*height
;@@:lodsd
   ;xor eax,[esi-width*4]

   
;   mov [esi],eax
;loop @b
;;;;;;;;;;;;;;;;;;;
 
;@@:invoke GetDC,0                                                          ;Ïîëó÷àåì Device Context ðàáî÷åãî ñòîëà
 ;  invoke SetDIBitsToDevice,eax,0,0,width,height,0,0,0,height,Raster,bmi,0 ;Êîïèðóåì èçîáðàæåíèå èç ïåðåìåííîé Raster íà ýêðàí
;   invoke GetAsyncKeyState,VK_ESCAPE                                       ;Ïðîâåðÿåì ñîñòîÿíèå êëàâèøè ESCAPE
;   test   eax,eax                                                          ;Åñëè íå íàæàòà
;jz @b                                                                     ;Ïåðåõîäèì íà ìåòêó @@
.quit:
invoke ExitProcess,0       ;Âûõîä èç ïðîãðàììû
 
.data
    pFileBytes   dd 0
    dwFileSize   dd 0 
    dwNumLoaded  dd 0 
    achFileName  db '111.txt',0


Raster  rd width*height

bmi     BITMAPINFOHEADER sizeof.BITMAPINFOHEADER,width,-height,1,24,0,width*height*3

Raster1  db 'C',0
.end start 
    
Post 31 Oct 2014, 19:42
View user's profile Send private message Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1419
Location: Toronto, Canada
AsmGuru62
Please try your code in debugger.
The file "111.txt" may be not in the working directory of the program.
Try to use the full path for the file.
Post 31 Oct 2014, 20:01
View user's profile Send private message Send e-mail Reply with quote
aasom65



Joined: 31 Oct 2014
Posts: 4
aasom65
All woking!!! I make mirror picture left right and up down and all woking,thanks!!!
Code:
format PE GUI 5.0

include 'win32wx.inc'

width  = 1280
height = 1024

.code
start:                         ;Òóò ìîæíî ðèñîâàòü

    ; Open file and save its handle into EBX 
    ; 
    invoke    CreateFileA, achFileName, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, 0 
    mov       ebx, eax 
    ; 
    ; If file is not opened - get out! 
    ; 
    cmp       eax, INVALID_HANDLE_VALUE 
    je        .quit 
    ; 
    ; ESI = file size in bytes 
    ; 
    invoke    GetFileSize, ebx, 0 
    mov       esi, eax 
    mov       [dwFileSize], eax 
    ; 
    ; Allocate memory for the file contents 
    ; EDI = pointer to that buffer 
    ; 
    invoke    VirtualAlloc, 0, esi, MEM_RESERVE or MEM_COMMIT, PAGE_READWRITE 
    mov       edi, eax 
    mov       [pFileBytes], eax 
    ; 
    ; If allocation fails - close file and get out! 
    ; 
    test      eax, eax 
    jz        .close_file 
    ; 
    ; Read the file into buffer and then close file. 

    invoke    ReadFile, ebx, Raster, [dwFileSize], dwNumLoaded, 0
    invoke    CloseHandle, ebx 
    ; 
    ; Now the file is fully loaded at the address in EDI... do whatever... 
    ; 
    nop 
    nop 
    nop 
    nop 
    nop 
    ; 
    ; Release memory and quit 
    ; 
    invoke    VirtualFree, [pFileBytes], 0, MEM_RELEASE 


.close_file: 
    invoke    CloseHandle, ebx 



;invoke  MessageBox,0, Raster,0,MB_OK ;âûâîäèì ñîîáùåíèå

mov  esi,Raster           ;ïåðåìåííàÿ Raster ñîäåðæèò èôîðìàöèþ î öâåòå ïèêñåëåé
;add  esi,width*4
;mov  dword[esi-4],255
mov  ecx,(width-1)*height
@@:lodsd
   ;xor eax,[esi-width*4]
;   mov eax,[esi]
   ;mov [esi],eax
loop @b
;;;;;;;;;;;;;;;;;;;
 
@@:invoke GetDC,0                                                          ;Ïîëó÷àåì Device Context ðàáî÷åãî ñòîëà
   invoke SetDIBitsToDevice,eax,0,0,width,height,0,0,0,height,Raster,bmi,0 ;Êîïèðóåì èçîáðàæåíèå èç ïåðåìåííîé Raster íà ýêðàí
   invoke GetAsyncKeyState,VK_ESCAPE                                       ;Ïðîâåðÿåì ñîñòîÿíèå êëàâèøè ESCAPE
   test   eax,eax                                                          ;Åñëè íå íàæàòà
   jz @b                                                                     ;Ïåðåõîäèì íà ìåòêó @@
.quit:
invoke ExitProcess,0       ;Âûõîä èç ïðîãðàììû
 
.data
    pFileBytes   dd 0
    dwFileSize   dd 0 
    dwNumLoaded  dd 0 
    achFileName  db 'f:\222.bmp',0


Raster  rd width*height

bmi     BITMAPINFOHEADER sizeof.BITMAPINFOHEADER,width,-height,1,24,0,width*height*3

Raster1  dd ?
.end start    


Description:
Download
Filename: pack.zip
Filesize: 161.46 KB
Downloaded: 45 Time(s)

Post 01 Nov 2014, 07:15
View user's profile Send private message Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1419
Location: Toronto, Canada
AsmGuru62
It is good that i works, however, 2 problems:
1. CloseHandle called twice
2. VirtualFree must be called just before ExitProcess.

Basically, memory is getting released and then your code runs on a released memory.
Post 01 Nov 2014, 12:49
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


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.