News:

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

How to go about this?

Started by safe, June 14, 2006, 12:37:21 PM

Previous topic - Next topic

safe

How would it be possible locate the EOF using apis in masm?

I have read the rules and understand this may be touching shakey ground so i'll explain what i'm up to:

I wish to implement this as a function to "trim" a PE EXE file if need be, so if unnecessary bytes are added to make the filesize bigger,
it will be cut off.
This is part of a bigger compression tool me and a friend are making for coursework, and i promised i'd sort this out.


Regards in advance.

safe

P1

safe,

Welcome aboard  :U

'Search' and Google are your best friends in programming.

Win32 programming, try MSDN site for reference.

The Win32 API is GetFileSize, the EOF is the last byte.

Regards,  P1  :8)

safe

Thank you very much for the reply, i have googled and msdn'd it and i know a little more than i did before.
but for example,
API's like: ReadFile/WriteFile don't have a pointer to where to start Reading/Writing bytes, how would you implement this?
And how would you go about removing the unneeded bytes? What APIs and such.
Sorry, my friend ismuch more experienced, but he says i have to figure this one out :P
Thanks in advance,

Regards,

Safe

Casper

Casper says...

You are not correct.  ReadFile reads from the current offset into the file as denote by the file pointer.  You need to research MSDN or win32.hlp

hutch--

safe,

What you need to do is learn the PE format and in particular the MZ and PE headers followed by section headers. part of what you are doing is file reconstruction BEFORE you compress various sections and this stuff you must get right.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

P1

Quote from: safe on June 14, 2006, 03:52:29 PMAPI's like: ReadFile/WriteFile don't have a pointer to where to start Reading/Writing bytes, how would you implement this?
invoke SetFilePointer, hErrorFile, 0, NULL, FILE_END

You are not reading enough or you are skimming too quickly.  It's best to develope good research habits.

Regards,  P1  :8)

ToutEnMasm

Hello,
EOF is only in basic.
In asm , you have to know the size of the file.
If you don't know how to get the size , use
                         invoke FindFirstFile,and close the handle
In the stucture WIN32_FIND_DATA.nFileSizeLow you have the size of the file.
If it is in memory, start pointer + size = max value of the pointer
                              ToutEnMasm

Dasar

hi safe

as hutch said, you have to learn about PE format...

some files have data appended at the end of them, so if you want to read the orginal file only, without the appended data, you have to put the file pointer at the last section header, and read that section, and then get the sum of ( PointerToRawData + SizeOfRawData ) , so you will get the orginal file size....

if you want to get the size of appended data, then you have to get the complete file size ( orginal file size + size of appended data ) with the API GetFileSize, or as ToutEnMasm said, then the appended data size will be : ( Compelte file size - orginla file size )

you can't understand this, if you don't know about PE...

btw, PE format is prety easy ^_^

hope this help ^_^

that's all   : )


- Dasar