flat assembler
Message board for the users of flat assembler.

Index > Windows > Return Value Of Function

Goto page Previous  1, 2, 3  Next
Author
Thread Post new topic Reply to topic
Picnic



Joined: 05 May 2007
Posts: 1396
Location: Piraeus, Greece
Picnic 03 Feb 2017, 09:23
@Trentie89 deactivate your antivirus (if you have one) and try to compile again.
Post 03 Feb 2017, 09:23
View user's profile Send private message Visit poster's website Reply with quote
Trentie89



Joined: 01 Feb 2017
Posts: 26
Location: Perth, Australia.
Trentie89 04 Feb 2017, 02:09
That doesn't work either, thanks bro. I Think it has something to do with the compiler, because when I modify other code, it says illegal instruction ''.code" etc... Weird.....

Maybe its my windows 10 how its configed or something? The antivirus thing sounds right came with McAfee I just deactivated it(real time scanning) and nope.... Hmm..... Thanks again, asm file attached.


Description: ASM File.
Download
Filename: findwindowtwo.rar
Filesize: 298 Bytes
Downloaded: 428 Time(s)


_________________
I Am the greatest.!. ( NOT YET ).
Post 04 Feb 2017, 02:09
View user's profile Send private message Reply with quote
Walter



Joined: 26 Jan 2013
Posts: 155
Walter 04 Feb 2017, 05:16
Image
So much for "A picture is worth a thousand words."


Last edited by Walter on 05 Feb 2017, 01:48; edited 1 time in total
Post 04 Feb 2017, 05:16
View user's profile Send private message Reply with quote
fasmnewbie



Joined: 01 Mar 2011
Posts: 555
fasmnewbie 04 Feb 2017, 05:51
You have corrupt formatting when copy-pasting the code directly from this board. Here's the output I get from my library (mem_load + prnstr)

Code:
include 'win32axp.inc'

.codeáá

áástart:áá
áááááááinvokeááFindWindow,NULL,"MyFile.txtá-áNotepad"á

ááááááá.ifáeaxá<>á0á
ááááááá         invokeááMessageBox,HWND_DESKTOP,"WindowáFound!"á,"FindWindow",MB_OKá
ááááááá.endif

áááááááááinvokeááExitProcess,0
.endástart
á    


The remedy is to re-type everything on a new file.
Post 04 Feb 2017, 05:51
View user's profile Send private message Visit poster's website Reply with quote
Trentie89



Joined: 01 Feb 2017
Posts: 26
Location: Perth, Australia.
Trentie89 04 Feb 2017, 12:19
wow thanks man. Ill do it the non-cheating way now. Wink. Your a legend. Thanks heaps.
Post 04 Feb 2017, 12:19
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20414
Location: In your JS exploiting you and your system
revolution 04 Feb 2017, 13:43
Wow, how did all those non-breaking spaces get in there? Some type of "helpful" browser extension?

Strangely include was the only one that managed to not have 0xa0, so why did it fail?
Post 04 Feb 2017, 13:43
View user's profile Send private message Visit poster's website Reply with quote
Trinitek



Joined: 06 Nov 2011
Posts: 257
Trinitek 04 Feb 2017, 16:30
Tried copying from Edge and I didn't get any 0xA0's. Confused What kind of browser extension would even mess with that?
Post 04 Feb 2017, 16:30
View user's profile Send private message Reply with quote
Trentie89



Joined: 01 Feb 2017
Posts: 26
Location: Perth, Australia.
Trentie89 05 Feb 2017, 01:31
I Hope none that is fucking too badly with my code, Trinitek. Now I know that its formatting errors that produce those unusual responses from FASM's compiler.

Thanks to the great help of fasmnewbie(fasmpro) :-p. Now I can start learning this excellent language again, why waste your time with high-level compilers when you can create/code such beautifully pure executables with no metadata. Very Happy. Will be posting here lots, hopefully, as i learn more, i can help out more, whats the best fasm tutorial.???????. Trent.
Post 05 Feb 2017, 01:31
View user's profile Send private message Reply with quote
Trentie89



Joined: 01 Feb 2017
Posts: 26
Location: Perth, Australia.
Trentie89 05 Feb 2017, 03:10
Hi Guys,

Instead of starting a new thread, I might on as well keep this one running with some newbie questions, I wanted to change the text of a window if found, I can only do that if the window is opened by my own process right.?. I am having some issues with CreateProcess, the code below compiles, but the MessageBox doesn't even show up. Hmmmmm. Weird.

Code:
include 'win32ax.inc'

.code

start:
sinfo STARTUPINFO
pinfo PROCESS_INFORMATION

meemul db 'C:\Users\Trent\Desktop\HELLO.EXE',0
progpath db 'C:\Users\Trent\Desktop\HELLO,EXE',0

 invoke CreateProcess,meemul,progpath,NULL,NULL,FALSE,NORMAL_PRIORITY_CLASS,NULL,NULL,sinfo,pinfo
invoke MessageBox,HWND_DESKTOP,"Process Manufacturized.","Process Machined.",MB_OK
invoke ExitProcess,0
.end start      


What do y'all reckon.?.
Cheers dudes. Trent.
Post 05 Feb 2017, 03:10
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20414
Location: In your JS exploiting you and your system
revolution 05 Feb 2017, 03:56
You have data immediately following the start label. So the CPU will try to execute your data, that is never a good thing.

Move your data away from the code, perhaps into its own data section.
Code:
include ...

.data

sinfo ...
etc.

.code

start:
;code goes here
.end start    
Post 05 Feb 2017, 03:56
View user's profile Send private message Visit poster's website Reply with quote
Trentie89



Joined: 01 Feb 2017
Posts: 26
Location: Perth, Australia.
Trentie89 05 Feb 2017, 04:43
Thanks Legend.....

I Am a really new beginner with ASM/Fasm, but you guys have solved my
two problems so far. I'm sure ill have new questions, but ill keep them to this
thread. Hope that you guys have an awesome day/and or night. Smile. Trent.
Post 05 Feb 2017, 04:43
View user's profile Send private message Reply with quote
Trentie89



Joined: 01 Feb 2017
Posts: 26
Location: Perth, Australia.
Trentie89 07 Feb 2017, 04:34
Hey Guys,

As you probably know, I am working around process functions here with FASM, I Want to learn all about process creation and handles and what not, and even be able to write data to a processes memory, you get the gist, or even read process memory. My code below is my attempt at trying to open a process with CreateProcess and then change its window text. It doesn't work, can you tell me whats happening.?. Thanks legends.

Code:
include 'win32ax.inc'

.data

meemul db 'C:\Users\Trent\Desktop\Assembly\fasmw17159\EXAMPLES\DIALOG\DIALOG.EXE',0
progpath db 'C:\Users\Trent\Desktop\Assembly\fasmw17159\EXAMPLES\DIALOG\DIALOG.EXE',0

sinfo STARTUPINFO
pinfo PROCESS_INFORMATION


.code

start:

invoke CreateProcess,meemul,progpath,NULL,NULL,FALSE,NORMAL_PRIORITY_CLASS,NULL,NULL,sinfo,pinfo
invoke SetWindowText,eax,"New Text!"
invoke MessageBox,HWND_DESKTOP,"Process Manufacturized.",eax,MB_OK
invoke ExitProcess,0
.end start    
Post 07 Feb 2017, 04:34
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20414
Location: In your JS exploiting you and your system
revolution 07 Feb 2017, 05:28
You need to check the return values for each API that you call. Don't simply assume that they always succeed. The return value will give you information as to why it may have failed. You can either print the value to the screen, or better use a debugger to follow the progress.

BTW: For your particular problem, you don't have any mechanism to wait for the target process to finish initialising. In a multi-threaded OS things won't necessarily happen in any particular order. The target process may be setting the title after you set it, or it may happen in the reverse order. Also, your OS might be limiting your ability to change the target process due to security restrictions. You have passed a NULL security descriptor and your defaults might be to block remote tasks from making changes. Anyhow, the return value from each API will tell you what is happening.
Post 07 Feb 2017, 05:28
View user's profile Send private message Visit poster's website Reply with quote
Trentie89



Joined: 01 Feb 2017
Posts: 26
Location: Perth, Australia.
Trentie89 17 Feb 2017, 06:39
Code:
include 'win32ax.inc'

.data

meemul db 'C:\Users\Trent\Desktop\Assembly\fasmw17159\EXAMPLES\DIALOG\DIALOG.EXE',0
progpath db 'C:\Users\Trent\Desktop\Assembly\fasmw17159\EXAMPLES\DIALOG\DIALOG.EXE',0

sinfo STARTUPINFO
pinfo PROCESS_INFORMATION


.code

start:

invoke CreateProcess,meemul,progpath,NULL,NULL,FALSE,NORMAL_PRIORITY_CLASS,NULL,NULL,sinfo,pinfo
invoke SetWindowText,eax,"New Text!"
invoke MessageBox,HWND_DESKTOP,"Process Manufacturized.",eax,MB_OK
invoke ExitProcess,0
.end start                           


The msg box title says "Error". Is their a more specific function i could use to check the
error in more greater detail.?. I Know my OS(Windows 10) might not let me set the window
text even if i have created the process in my very own code. Do i need to pass a specific
security descriptor when calling CreateProcess in order to be able to change the child processes
window text.?. I Cant find much info on process functions on this board, or anywhere, not that i
am anywhere near an advanced Assembly programmer, they seem to be advanced functions
originally made by microsoft for developers wishing to create debuggers. Can you help me out.?.

God bless Ya and yours.!.

Trent.
Post 17 Feb 2017, 06:39
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20414
Location: In your JS exploiting you and your system
revolution 17 Feb 2017, 07:03
You have to convert the numeric code in EAX to text form (you might want either hex or decimal (or both) format(s)). If you pass EAX directly then the API thinks it is a pointer to some memory location with the text to show.

Also, you still need to check the return value from CreateProcess, it might have failed. You can do "CMP EAX,0" and then "JE some_label", or whatever code makes sense, and then show error messages when necessary.
Post 17 Feb 2017, 07:03
View user's profile Send private message Visit poster's website Reply with quote
Trentie89



Joined: 01 Feb 2017
Posts: 26
Location: Perth, Australia.
Trentie89 17 Feb 2017, 07:12
I Dont think that CreateProcess failed, as it does indeed launch the process. As a newbie as you know to ASM, can you please tell me how to convert eax to text.?. Thanks champ.


BTW: I Am on a major learning curve here, what are some great books to read to get to know FASM.?. I Intend on making it my second language after PHP(Im a professional at that, been doing it for 13 years). Not to make people angry, its just as a beginner i have lots of questions, and thanks to awesome people like you others can learn new languages and put their skills to the limit.!. I Only ever intend to master ASM, along with PHP which i have already mastered.

Trent.
Post 17 Feb 2017, 07:12
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20414
Location: In your JS exploiting you and your system
revolution 17 Feb 2017, 07:37
When your code runs, your code doesn't know if it fails. Only you, as the viewer knows. So it is still a good idea to check the return value in the code so that the code can take the appropriate action.

But anyhow, to convert numbers to text you can use the API wsprintf, or link to MSVCRT and use printf.
Code:
cinvoke wsprintf,addr dest_buff,'Some value = %08x',eax    
Post 17 Feb 2017, 07:37
View user's profile Send private message Visit poster's website Reply with quote
Trentie89



Joined: 01 Feb 2017
Posts: 26
Location: Perth, Australia.
Trentie89 17 Feb 2017, 10:15
I'm starting to think that its a Windows 10 thing. Unless someone can be kind enough to somehow show me otherwise. Heres me code, i called GetLastError. And displayed it on a messagebox, here is the code and screenshot.

Code:
include 'win32ax.inc'

.data

meemul db 'C:\Users\Trent\Desktop\Assembly\fasmw17159\EXAMPLES\DIALOG\DIALOG.EXE',0
progpath db 'C:\Users\Trent\Desktop\Assembly\fasmw17159\EXAMPLES\DIALOG\DIALOG.EXE',0

sinfo STARTUPINFO
pinfo PROCESS_INFORMATION


.code

start:

invoke CreateProcess,meemul,progpath,NULL,NULL,FALSE,NORMAL_PRIORITY_CLASS,NULL,NULL,sinfo,pinfo
invoke SetWindowText,eax,"New Text!"
invoke MessageBox,HWND_DESKTOP,GetLastError,"Show Error",MB_OK
invoke ExitProcess,0
.end start                                            


Description:
Filesize: 51.53 KB
Viewed: 11708 Time(s)

error2.jpg



_________________
I Am the greatest.!. ( NOT YET ).
Post 17 Feb 2017, 10:15
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20414
Location: In your JS exploiting you and your system
revolution 17 Feb 2017, 10:59
GetLastError is just an address pointer to data. So trying to print it as text won't be useful to you.

You can invoke GetLastError to retrieve the error string and then pass the return address to MessageBox.
Post 17 Feb 2017, 10:59
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20414
Location: In your JS exploiting you and your system
revolution 17 Feb 2017, 11:02
But even if you do all that, you still have the problem of the race condition I explained above. You have to synchronise with the target application to make sure it is ready to set the title.

Also, the process itself doesn't have window text to display, only the windows within the application have title bars. So you have to communicate with the target app to find its window handles and then set the titles there.
Post 17 Feb 2017, 11:02
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2, 3  Next

< 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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.