Jump to content
Tuts 4 You

How to control CMD console?


LCF-AT

Recommended Posts

Posted

Hi again, :)


 


yeah.......I got some luck and found out (yes by myself) how to do it with that tray now after long testings.Just needed to add MF_OWNERDRAW flag at the ModifyMenu API at WM_SHELLNOTIFY message to get WM_MEASUREITEM & WM_DRAWITEM in my main routine so subclassing wasn't necessary.Great!But anyway,so first I got success with subclassing the main DLG itself and later I found that problem with the flag to set it on right MSG position to get it received.Man man man man man you!Such a little pipifax issue and you work hours & days on it. :) Below my picture now...hmmmm isn't it looking nice now.Just delicious. :)


 


greetz


post-27695-0-56427800-1440288902.png

  • 2 weeks later...
Posted

Hi guys its me again,


 


so today I have again a question we talked about it in the past but now its a bit different and need to find a simple solution if possible so thats the reason why I do ask again now.


 


I am talking again about using CreateProcess API to start a process with 2 files (cmd tool + player tool).Now I wanna know whether there is any easy way to connect both files with each other so that one file checks the other file whether its running or not.So the main thing is that the cmd tool mostly will not close by itself after I did close the other player file so that I need to exit the cmd tool manually after and this sucks.Now I want that both files get closed if I close one of the both files (cmd tool or player).This time I also don't wanna get any infos by the cmd tool or something as before so this time I just wanna know how to close them.It would be also cool if I don't need to write any code to watch the processes as before and to check the PID IDs etc if possible.So if I still need to write such code to check processes etc then I should need to use new created threads for that and thats a bit much work if I start for example 5 x a CMD tool + Player instance etc you know.


 


Would be nice if you could help again with some infos how to handle this now to perform a exit of cmd tool if I exit the player tool.


 


Thanks again


Posted

I am talking again about using CreateProcess API to start a process with 2 files (cmd tool + player tool).

Now I want that both files get closed if I close one of the both files (cmd tool or player).

Maybe you can help this: CreateJobObject + AssignProcessToJobObject + TerminateJobObject

Posted

Hi,


 


I am not sure whether using CreateJobObject / etc will help or is a good idea so on net I see some people have trouble to use it with other OS.At the moment I created a own thread to watch the processes what does check for the player name and then checks this for ParentProcessID to see whether CMD tool pid is inside and if yes then both are still running = OK and keep untouched.Now if I close the player manually via mouse then my code does check again the processes (every second) and now it gets same results but this time player pid is gone and the entire processes gets checked till end and exactly here after end of Process32Next I do Open & Terminate the process of CMD tool.So normaly all is working fine with that but I see also some problems.


 


1.) If I close the player manually then in some special cases the player is still running in background and waiting for response of CMD tool and if the player isn't closed then its still present in processes list = CMD tool will not terminated now.Just if I force to close player from taskmanger then CMD tool gets also closed as it should.Thats one problem.


 


2.) Also if player gets exit normaly and CMD is running alone then it gets terminated (as it should) by my code and also removed from process list BUT CMD window is still there & active (?!?) and does not go away from alone and I need to close it manually.So this happens if the CMD tool does wait for any response and if it gets nothing to work with then it loops a very long time and this sucks.


 


Thats problems so far.So I think also if I should use CreateJobObject way then I will have same problems or?


 


greetz


Posted

Hi again,


 


new question.Does anyone have any examples how to create a sidebar into popup menu?Of course there is again nothing to find for ASM only other languages where I don't really can follow every step etc like this...



http://www.codeproject.com/Articles/8645/Menu-sidebar-made-easy

..and I got no Sidebar APIs etc.Maybe you got any ASM example or something where I can work with.


 


Thank you


Posted

Hi raggy,


 


I had a look but isn't really same what I am looking for to create a sidebar as you can see on the picture of the link I did postet.With the masm example I can just draw edges which I can fill with any colors etc.Maybe you got another example or idea for me later. :)


 


Edit: Thanks for the Ez src so the look is very nice. :)


 


Thanks again and greetz


Posted (edited)

Hi LCF-ATSideBar Menu
I think that's what you want to.I hope I could help you. :unsure:Regards

SideBarMenu.rar

Edited by Black Rider
  • Like 1
Posted

Hello Black Rider,


 


thank you for creating this example for me. :) I got it working now.So I think using a picture sidebar + icons are maybe too much so in my case its not looking so well if I use both so maybe just using one of them is a better choice.Thanks again for that example and nice to see that another member did remember about that. :)


 


greetz


post-27695-0-48147300-1442160321.png

Posted

Hi guys,


 


new question: Does anyone of you has any good injector ASM source to inject dlls?Normaly I do use Winject for example but I want to build a small simple code to inject / de-ject in my app.Just asking before I try to write a own code etc.


 


Thanks


Posted

Hallo LCF-AT,


 


I've changed the code from the SideBar menu. So I like it better. :)


Now, the SideBar menu is without Picture + MF_OWNERDRAW for separators, have fun. :lol:


 


greetz


SideBarMenu2.rar

  • Like 2
Posted

@Black Rider


Nice, Thanks. Just one caveat. When you click Item 7, it will say Item 6 :partytime:



        .ELSEIF eax == 15
            invoke MessageBox, hWnd, addr Menu7,addr szAppName,MB_OK    
        .ELSEIF eax == 16
            invoke MessageBox, hWnd, addr Menu7,addr szAppName,MB_OK            
        .ENDIF

Regards,


Tony

Posted (edited)

@tonyweb


Thank you liked it. :) MessageBox is not bad, is just demo.


 


Regards,


Black Rider

Edited by Black Rider
Posted

Hi again,


 


thanks for your new Sidebar Demo Black Rider. :)


Yes this is better without to use a picture.Also I didn't know that you also can rotate text. :) Nice.Just keep going so maybe you have another & more nice other demo sources you wanna post later in your own topic if you want etc so that would be nice to get some more ASM input. :)


 


greetz


  • 2 weeks later...
Posted

Hi guys,


 


I have some questions again and need some help.I am trying to work with a dll what used many APIs which I wanna use in my app.Unfortunately the source / libs are only to get C or C+ etc and not in MASM so that I have to use the dll itself for me.


 


Dll is called librtmp.dll and was made by..


https://rtmpdump.mplayerhq.hu/


...to work with rtmp/* datas.All in all there are many different versions to get now you can find on internet.There is also CMD tool called rtmpdump what you can use with different paramters to stream such rtmp/* links.Now I made a very simple test code to check out whether I get it working to download such stream just using right APIs and its working so far.The problem I have now is how to pipe the stream into a player using & set stdout instead to download.I don't know how to do this and unfortunately I can't debug the rtmpdump tool itself in Olly if I use it with arguments so if I do then the stream datas get piped into CMD window itself instead to the player.The only thing I can see during debugging is that rtmpdump used the _setmode (msvcrt) API if I use a player as output instead file.



0022B8BC 00450863 /CALL to _setmode from rtmpdump.0045085E
0022B8C0 00000001 |handle = 0x1
0022B8C4 00008000 \amode = O_RDONLY|O_BINARY|SH_COMPAT0x0

The basic test code I made looks so....



CreateFile
WSAStartup
------------------------------
RTMP_Alloc
RTMP_Init
RTMP_SetupURL "rtmp://live.hkstv.hk.lxdns.com/live/hks"
RTMP_Connect
RTMP_ConnectStream
/////////////////////
LOOP:
RTMP_Read ; till return is 0
------------------------------
WriteFile ; write data to file
------------------------------
CloseHandle
------------------------------
RTMP_Close
RTMP_Free
------------------------------
WSACleanup

....and is also working as I told before to download the stream datas into a file but my question is how to pipe the datas to a extern player with stdout so that my player gets the datas to play it you know.Maybe you can help me with that problem I have.Thanks.


 


On Github you can find many stuff about rtmpdump / librtmp like here..


https://github.com/mstorsjo/rtmpdump/tree/master/librtmp


https://github.com/K-S-V/Scripts/releases


 


greetz


  • 1 month later...
Posted

Hi guys,


 


short question again: Does anyone of you have any ready code to decode URLs?You know URLs who using %3F = ? %2F = / etc to get a clean full URL.Same as the Notepad++ tool can do (MIME tools / URL Decode option).Maybe you know or have something for this already what you could post...



push ASCII string
invoke URL_DECODE

...or maybe you know any API xy what can do this already (I don't know any yet) which I could use or any lib or whatever. :)


 


Thank you


Posted

Writing a parser for this kind of thing is not so hard. In principle what you do is:


 


for each character (ch) in encoded_url do:
if ch == '%' then
    consume 2 characters
    convert from hex to byte
    put byte in decoded_url
else
    put ch in decoded_url

Posted

Hi,


 


ok thanks but what is if % is not a part of URL to decode like %% or %123%?I thought there is any code who does check for possible things to decode.


 


greetz


Posted (edited)

LCF-AT: I don't know the exact specification of the URL decoding, but you can add extra cases for things like this.

if ch == '%' && nextch == '%' then    put '%' in decoded_url
EDIT: It looks like you cannot add a % directly to the URL. You need to use %25 for this (just hex encoding for '%')

http://www.w3schools.com/tags/ref_urlencode.asp

Edited by Mr. eXoDia
Posted

 

 

; Compile - 
; ml /c /coff /Cl target.asm
;link /subsystem:console target.obj
.486p
.model	flat, stdcall
option	casemap: none

include		\masm32\include\msvcrt.inc
includelib	\masm32\lib\msvcrt.lib

.data
	HexFormat    db "%2x", 0
	DecodeString db "https%3A%2F%2Fforum.tuts4you.com%2Ftopic%2F36791-how-to-control-cmd-console%2F%3Fpage%3D9", 0
.data?

.code
IsHex proc X:DWORD
        Local ReturnValue      :Dword
		Cmp X,                 2fh
		Jle Upper
Lower:
		Cmp X,                 39h
		Jle ReturnPos
Upper:
		Cmp X,                 60h
		Jle Numerical
		Cmp X,                 66h
		Jle ReturnPos
Numerical:
		Cmp X,                 40h
		Jle ReturnNeg
		Cmp X,                 46h
		Jle ReturnPos
		Jmp ReturnNeg
ReturnPos:
		Mov ReturnValue,       1
ReturnNeg:
		Mov Eax,               ReturnValue 
		Leave
		Retn
IsHex endp

Decode proc InBuffer:Dword, OutBuffer:Dword
		Local EndPointer       :Dword
		Local OPointer         :Dword
		Local CPointer         :Dword
		Local IntC             :Dword
		Local ReturnValue      :Dword
		Mov Eax, InBuffer
		Invoke crt_strlen,     Eax
        Add Eax, InBuffer
        Mov EndPointer,        Eax
        Mov Eax,               OutBuffer
        Mov OPointer,          Eax ; ebp -4 is *O
BeginLoop:
        Mov Eax,               InBuffer
        Cmp Eax,               EndPointer
        Ja Break
		Mov Eax,               InBuffer
		Movsx Eax,             Byte Ptr Ds:[Eax]
		Mov IntC,              Eax 
		Inc InBuffer
		Cmp IntC,              2Bh
		Jnz Plus
		Mov IntC,              20h
		Jmp OutBufferCheck
Plus:
		Cmp IntC,              25h
		Jnz OutBufferCheck
		Mov Eax,               InBuffer
		Inc InBuffer
		Movsx Eax,             Byte Ptr Ds:[Eax]
		Invoke IsHex,          Eax
		Test Eax,              Eax                           
		Je ReturnNeg              
		Mov Eax,               InBuffer
		Inc InBuffer
		Movsx Eax,             Byte Ptr Ds: [Eax]
		Invoke IsHex,          Eax
		Test Eax,              Eax                           
		Je ReturnNeg
		Lea Eax,               IntC           
		Mov Ecx,               InBuffer          
		Sub Ecx,               2                              
		invoke crt_sscanf,     Ecx, offset HexFormat, Eax
		.If ( Eax  != 0)
		    Jmp	OutBufferCheck
		.endif
ReturnNeg:
		Mov ReturnValue,       -1
		Jmp Return
OutBufferCheck:
		Cmp OutBuffer,         0
		Je LoopAgain
		Mov Edx,               OPointer
		Mov Eax,               IntC
		Mov Byte Ptr Ds:[Edx], Al
LoopAgain:
		Lea Eax,               OPointer
		Inc Dword Ptr Ds:[Eax]
		Jmp BeginLoop
Break:
		Mov Eax,               OutBuffer
		Mov Edx, 	           OPointer
		Sub Edx,               Eax
		Mov Eax,               Edx
		Mov ReturnValue,       Eax
Return:
		Mov Eax,               ReturnValue
		Leave
		Retn
Decode endp 

start proc
	Local CharPointer  :Dword
	
    Invoke crt_strlen, Offset DecodeString
	
	Add Eax, 1
	
	Invoke crt_malloc, Eax
	
	Mov CharPointer,   Eax

	; Arg1 = String you want to decode.
	; Arg2 = Caller allocated memory buffer. Decoded string is outputed here.
	; Ret  = Number of decoded bytes
	Invoke Decode,     Offset DecodeString, CharPointer
	
	.If (Eax > 0)
	
		Mov Eax,   CharPointer
	
		Invoke     crt_printf, Eax
		
	.Endif 
	
	Mov Eax,           CharPointer
	
	Invoke crt_free,   Eax
	
    Mov Eax,           0
    Leave
    Retn
start endp
end start






I needed some masm excersize so here u go LCF, I translated this to masm 4 u from my C mime lib

That link from Mr. Exodia I think is pretty bad, it implies a lot of stuff gets encoded that doesnt. A-F, a-f, and some others will never get encoded, so it's pointless to have them in that chart.

Read rfc3986, start from pg. 10, it explains how the encoding works, when to use it, etc. application/x-www-form-urlencoded - https://www.ietf.org/rfc/rfc3986.txt

We use our own libs for this & although extremely overpriced, closed source, & paid, chillkats libs should do everything u need. He has code samples in pretty much every language too. Except asm haha.

PS - hey, teddy, my code spacing is getting F$%#$@%$#%@$% up!!!!

  • Like 1
Posted
10 hours ago, simple said:

PS - hey, teddy, my code spacing is getting F$%#$@%$#%@$% up!!!!

What syntax highlighting did you choose to use in your code tags?

Ted.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...