(http://img165.imageshack.us/img165/5741/97192591lf7.gif)
How would I fix the shwiconEM.exe and vmnetdhcp.exe lines' disalignment? I figure I can do it by setting my own tab stops, but how? The output looks so messy. Right now I'm using two \t's.
It ain't dynamic. Get over it.
Quote from: rabbit on October 23, 2007, 07:03 AM
It ain't dynamic. Get over it.
Use CSuperBrewProcessListerTabs, shits fyre
The best way is probably to use printf()-style formatting parameters (you can do it in C++ too, but I don't know how)
printf("%32s %d\n");
That'll print the string in a 32-character column. I forget whether it aligns the string left or right, but you can probably play around with it and get it right.
The other option is to manually do it:
int i;
printf("%s", str);
for(i = 0; i < 32 - strlen(str); i++)
printf(" ");
printf("\n");
There's probably a better way to do that, but whatever. :)
Quote from: iago on October 23, 2007, 08:52 AM
The best way is probably to use printf()-style formatting parameters (you can do it in C++ too, but I don't know how)
printf("%32s %d\n");
That'll print the string in a 32-character column. I forget whether it aligns the string left or right, but you can probably play around with it and get it right.
The other option is to manually do it:
int i;
printf("%s", str);
for(i = 0; i < 32 - strlen(str); i++)
printf(" ");
printf("\n");
There's probably a better way to do that, but whatever. :)
You were right-- it alligns to the right, i wonder how i would get it to the left? (actually i dont think i can :/) So yeah, padding it with spaces for every char it doesn't take up is the best idea. Thanks for helping.
C# was the last language I remember you to brown-nose. If not, port it yourself.
using System;
using System.Collections.Generic;
using System.Text;
namespace StringPadding
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("String padder");
Console.WriteLine("A Joe[x86] Production!");
Console.WriteLine();
Console.WriteLine(padStringRight("Brew is an idiot.", 'x', 32));
Console.WriteLine();
Console.WriteLine("Press any key to exit.");
Console.ReadKey();
}
private static string padStringRight(string data, char padding, int length)
{
if (data.Length > length)
throw new ArgumentOutOfRangeException("length", "length parameter is shorter than data's length.");
char[] ret = new char[length];
Array.Copy(data.ToCharArray(), ret, data.Length);
for (int i = data.Length; i < length; i++)
{
ret[i] = padding;
}
return new String(ret);
}
}
}
Quote from: Joex86] link=topic=17131.msg174150#msg174150 date=1193158913]
C# was the last language I remember you to brown-nose. If not, port it yourself.
What? I can't port that, I don't know C# at all. I never coded in C# or anything .NET for that matter, and I intend to never code in any .NET languages in my lifetime. And if you had read my last post you would have found that I've already got it figured out-- I just used a space padder like iago said to. I first learned about a space padder long ago, back when I was making columns for a listbox control in vb. I just never thought of using it for this (i figured sprintf would have something i didn't know about that does this, apparently not)
Also, nice coding practice:
return new String(ret);
Allocating heap memory for a string? And you don't even free it in main(). So what if the program is going to end and it wouldn't matter, it's just not a good idea to do that IMO.
Quote from: brew on October 23, 2007, 12:27 PM
Allocating heap memory for a string? And you don't even free it in main(). So what if the program is going to end and it wouldn't matter, it's just not a good idea to do that IMO.
C# is a garbage collected language. All classes are allocated using the new keyword, and are disposed of automatically when they are no longer referenced.
Quote from: iago on October 23, 2007, 08:52 AM
The best way is probably to use printf()-style formatting parameters (you can do it in C++ too, but I don't know how)
In C++ you use the stream operators found in the <iomanip> header. In this case, probably something like:
using namespace std;
cout << setw(32) << left << "foo" << setw(32) << left << "bar" << endl;
Quote from: brew on October 23, 2007, 09:59 AM
Quote from: iago on October 23, 2007, 08:52 AM
The best way is probably to use printf()-style formatting parameters (you can do it in C++ too, but I don't know how)
printf("%32s %d\n");
That'll print the string in a 32-character column. I forget whether it aligns the string left or right, but you can probably play around with it and get it right.
The other option is to manually do it:
int i;
printf("%s", str);
for(i = 0; i < 32 - strlen(str); i++)
printf(" ");
printf("\n");
There's probably a better way to do that, but whatever. :)
You were right-- it alligns to the right, i wonder how i would get it to the left? (actually i dont think i can :/) So yeah, padding it with spaces for every char it doesn't take up is the best idea. Thanks for helping.
np looking to help anytime!
Quote from: devcode on October 23, 2007, 01:01 PM
np looking to help anytime!
I'm pretty sure I was talking to iago
@K: I don't want to use any C++. I , personally, hate classes or anything OO of that sort.
Quote from: brew on October 23, 2007, 01:42 PM
Quote from: devcode on October 23, 2007, 01:01 PM
np looking to help anytime!
I'm pretty sure I was talking to iago
@K: I don't want to use any C++. I , personally, hate classes or anything OO of that sort.
what
Quote from: brew on October 23, 2007, 09:59 AM
Quote from: iago on October 23, 2007, 08:52 AM
The best way is probably to use printf()-style formatting parameters (you can do it in C++ too, but I don't know how)
printf("%32s %d\n");
That'll print the string in a 32-character column. I forget whether it aligns the string left or right, but you can probably play around with it and get it right.
The other option is to manually do it:
int i;
printf("%s", str);
for(i = 0; i < 32 - strlen(str); i++)
printf(" ");
printf("\n");
There's probably a better way to do that, but whatever. :)
You were right-- it alligns to the right, i wonder how i would get it to the left? (actually i dont think i can :/) So yeah, padding it with spaces for every char it doesn't take up is the best idea. Thanks for helping.
To align to the left I believe you specify a negative padding number:
printf("%-32s", s);
Quote from: Joex86] link=topic=17131.msg174150#msg174150 date=1193158913]
C# was the last language I remember you to brown-nose. If not, port it yourself.
Joe, first of all that's not the right approach, and even if it was, C# already has String.PadLeft (http://msdn2.microsoft.com/en-us/library/system.string.padleft.aspx) and String.PadRight (http://msdn2.microsoft.com/en-us/library/system.string.padright.aspx) methods that work on the instances of the strings they're changing.
The proper way to do it would be to use formatting strings. Format strings allow an alignment property to be set:
using System;
using System.Diagnostics;
using System.IO;
using System.ComponentModel;
class Program
{
static void Main(string[] args)
{
Console.WriteLine();
Console.WriteLine(" ===={ Process Viewer }====");
Console.WriteLine();
Console.WriteLine(" {0,24}{1,10}", "Image Name", " ID ");
Console.WriteLine();
Process[] processes = Process.GetProcesses();
int threads = 0;
foreach (Process p in processes)
{
try
{
Console.WriteLine(" {0,24}{1,10}", Path.GetFileName(p.MainModule.FileName), p.Id);
}
catch (Win32Exception)
{
Console.WriteLine(" {0,23}*{1,10}", p.ProcessName, p.Id);
}
threads += p.Threads.Count;
}
Console.WriteLine();
Console.WriteLine(" Total number of processes: {0}", processes.Length);
Console.WriteLine(" Total number of threads: {0}", threads);
Console.ReadLine();
}
}
Note: for processes that do not expose a main module (I was receiving ACCESS_DENIED errors), I have marked them with a * at the end of the process name.
Result:
(http://www.jinxbot.net/pub/brew_ps.jpg)
K: that (left alignment) is likely correct. .NET's formatting was based on C, and that's how you would left-align.
Quote from: K on October 23, 2007, 02:37 PM
To align to the left I believe you specify a negative padding number:
printf("%-32s", s);
Oh wow, that's just what i was looking for. :D
Mynd, I've noticed that people call blank writelines in order to space their lines out. Is there no '\n' in C# or something? That'd be pretty sad if there weren't
"\n" isn't a standard. Windows, for example, uses \r\n. Linux uses \n. iirc, Mac uses \r. So using println() guarantees, in a platform-independent way, that you'll get the proper newline character.
That may seem silly in C#, which is only typically run on Windows, but it's still a good habit. Plus, people might make silly mistakes like using "\n" instead of "\r\n" :P
Quote from: iago on October 23, 2007, 03:07 PM
Plus, people might make silly mistakes like using "\n" instead of "\r\n" :P
I always use \n instead of \r\n :(
Hey, how would i get a handle to the thread of another process?
Quote from: brew on October 23, 2007, 03:51 PM
Quote from: iago on October 23, 2007, 03:07 PM
Plus, people might make silly mistakes like using "\n" instead of "\r\n" :P
I always use \n instead of \r\n :(
Hey, how would i get a handle to the thread of another process?
www.g00gles.com
Quote from: devcode on October 23, 2007, 04:00 PM
Quote from: brew on October 23, 2007, 03:51 PM
Quote from: iago on October 23, 2007, 03:07 PM
Plus, people might make silly mistakes like using "\n" instead of "\r\n" :P
I always use \n instead of \r\n :(
Hey, how would i get a handle to the thread of another process?
www.g00gles.com
I lol'd.
Quote from: iago on October 23, 2007, 03:07 PM
"\n" isn't a standard. Windows, for example, uses \r\n. Linux uses \n. iirc, Mac uses \r. So using println() guarantees, in a platform-independent way, that you'll get the proper newline character.
That may seem silly in C#, which is only typically run on Windows, but it's still a good habit. Plus, people might make silly mistakes like using "\n" instead of "\r\n" :P
I think \r just returns the text-cursor to the beginning of whatever row it's on. While \n actually advances it one row.
The good thing about C# is that due to it being a standard, you're able to make certain assumptions about it's implementation across multiple platforms. It's pretty much guaranteed to be the same, as with Java.
Quote from: iago on October 23, 2007, 03:07 PM
"\n" isn't a standard. Windows, for example, uses \r\n. Linux uses \n. iirc, Mac uses \r. So using println() guarantees, in a platform-independent way, that you'll get the proper newline character.
That may seem silly in C#, which is only typically run on Windows, but it's still a good habit. Plus, people might make silly mistakes like using "\n" instead of "\r\n" :P
The
proper way to do it in C# is Environment.NewLine, unless you're dealing with the console, in which Console.WriteLine() deals with it for you.
Quote from: Joex86] link=topic=17131.msg174176#msg174176 date=1193210404]
Quote from: iago on October 23, 2007, 03:07 PM
"\n" isn't a standard. Windows, for example, uses \r\n. Linux uses \n. iirc, Mac uses \r. So using println() guarantees, in a platform-independent way, that you'll get the proper newline character.
That may seem silly in C#, which is only typically run on Windows, but it's still a good habit. Plus, people might make silly mistakes like using "\n" instead of "\r\n" :P
The proper way to do it in C# is Environment.NewLine, unless you're dealing with the console, in which Console.WriteLine() deals with it for you.
Not necessarily. Using Environment.NewLine, which is a string, could potentially require concatenation, which is not kosher (it can become expensive because strings are immutable). When possible, using a TextWriter's WriteLine or StringBuilder's AppendLine is preferable.
Quote from: brew on October 23, 2007, 03:51 PM
Quote from: iago on October 23, 2007, 03:07 PM
Plus, people might make silly mistakes like using "\n" instead of "\r\n" :P
I always use \n instead of \r\n :(
Hey, how would i get a handle to the thread of another process?
The functions you need are something like:
FindWindow() to get a handle to the window
GetWindowThreadProcessId() to get the process id (I am doing the names from memory, so I could be wrong on that)
OpenProcess() to get a handle to the process
Somebody can correct me if I'm mistaken.
Quote from: iago on October 24, 2007, 10:34 AM
The functions you need are something like:
FindWindow() to get a handle to the window
GetWindowThreadProcessId() to get the process id (I am doing the names from memory, so I could be wrong on that)
OpenProcess() to get a handle to the process
Somebody can correct me if I'm mistaken.
IIRC, OpenProcess returns a handle to the process, not the thread. Perhaps you were thinking of OpenThread? (that requires a thread ID, and GetThreadID requires a thread handle, what i wanted in the first place) I've found a good way to do this-- calling CreateToolhelp32Snapshot with flags TH32CS_THREAD (I thought at first i was going to have to use a kernel mode api for this one) then call OpenThread. Thanks anyways.
Quote from: brew on October 24, 2007, 10:51 AM
Quote from: iago on October 24, 2007, 10:34 AM
The functions you need are something like:
FindWindow() to get a handle to the window
GetWindowThreadProcessId() to get the process id (I am doing the names from memory, so I could be wrong on that)
OpenProcess() to get a handle to the process
Somebody can correct me if I'm mistaken.
IIRC, OpenProcess returns a handle to the process, not the thread. Perhaps you were thinking of OpenThread? (that requires a thread ID, and GetThreadID requires a thread handle, what i wanted in the first place) I've found a good way to do this-- calling CreateToolhelp32Snapshot with flags TH32CS_THREAD (I thought at first i was going to have to use a kernel mode api for this one) then call OpenThread. Thanks anyways.
guess g00gles musta worked out for you. lol @ kernel mode api, thats a good one
Out of curiousity, why do you need a handle to an already existing thread? When hacking a program most people create a thread within the process space.
Quote from: MyndFyre[vL] on October 24, 2007, 11:19 AM
Out of curiousity, why do you need a handle to an already existing thread? When hacking a program most people create a thread within the process space.
Creating a new thread in the remote process is one option but not the only one. You can get control of an existing thread using the GetThreadContext, SetThreadContext APIs and redirect execution. There are many ways to achieve the same thing..........................................
Quote from: devcode on October 24, 2007, 11:14 AM
Quote from: brew on October 24, 2007, 10:51 AM
Quote from: iago on October 24, 2007, 10:34 AM
The functions you need are something like:
FindWindow() to get a handle to the window
GetWindowThreadProcessId() to get the process id (I am doing the names from memory, so I could be wrong on that)
OpenProcess() to get a handle to the process
Somebody can correct me if I'm mistaken.
IIRC, OpenProcess returns a handle to the process, not the thread. Perhaps you were thinking of OpenThread? (that requires a thread ID, and GetThreadID requires a thread handle, what i wanted in the first place) I've found a good way to do this-- calling CreateToolhelp32Snapshot with flags TH32CS_THREAD (I thought at first i was going to have to use a kernel mode api for this one) then call OpenThread. Thanks anyways.
guess g00gles musta worked out for you. lol @ kernel mode api, thats a good one
Yes, I was looking into ZwQuerySystemInformation or something like that, I think it returned a pointer to struct in a struct that had a pointer to a list of all the thread ids.
MyndFyre: To pause execution of other programs, ofcourse. I find all the threads associated with the PID, then call SuspendThread on all of them.
Isn't it easier to use the debugging APIs?
Note: I don't know the debugging APIs, so this is me speculating.
Quote from: brew on October 24, 2007, 10:51 AM
Quote from: iago on October 24, 2007, 10:34 AM
The functions you need are something like:
FindWindow() to get a handle to the window
GetWindowThreadProcessId() to get the process id (I am doing the names from memory, so I could be wrong on that)
OpenProcess() to get a handle to the process
Somebody can correct me if I'm mistaken.
IIRC, OpenProcess returns a handle to the process, not the thread. Perhaps you were thinking of OpenThread? (that requires a thread ID, and GetThreadID requires a thread handle, what i wanted in the first place) I've found a good way to do this-- calling CreateToolhelp32Snapshot with flags TH32CS_THREAD (I thought at first i was going to have to use a kernel mode api for this one) then call OpenThread. Thanks anyways.
Ah, the original question was worded funny, "Hey, how would i get a handle to the thread of another process?"
I assumed you wanted to get a handle to the process. What I think you wanted to ask was how to get a handle to
a thread in another process.
Quote from: iago on October 24, 2007, 08:42 PM
Quote from: brew on October 24, 2007, 10:51 AM
Quote from: iago on October 24, 2007, 10:34 AM
The functions you need are something like:
FindWindow() to get a handle to the window
GetWindowThreadProcessId() to get the process id (I am doing the names from memory, so I could be wrong on that)
OpenProcess() to get a handle to the process
Somebody can correct me if I'm mistaken.
IIRC, OpenProcess returns a handle to the process, not the thread. Perhaps you were thinking of OpenThread? (that requires a thread ID, and GetThreadID requires a thread handle, what i wanted in the first place) I've found a good way to do this-- calling CreateToolhelp32Snapshot with flags TH32CS_THREAD (I thought at first i was going to have to use a kernel mode api for this one) then call OpenThread. Thanks anyways.
Ah, the original question was worded funny, "Hey, how would i get a handle to the thread of another process?"
I assumed you wanted to get a handle to the process. What I think you wanted to ask was how to get a handle to a thread in another process.
Question was fine and worded properly, else he would have asked "How would i get a handle to another process". You made a mistake and you're justifying it by partly blaming for their wording so, no doesnt work like that unfortunately. Nice try though, better luck next time
Quote from: devcode on October 24, 2007, 09:06 PMQuestion was fine and worded properly, else he would have asked "How would i get a handle to another process". You made a mistake and you're justifying it by partly blaming for their wording so, no doesnt work like that unfortunately. Nice try though, better luck next time
Uh, nope. Read brew's question, and then hopefully you'll understand iago's thoughts. You don't get
a handle to
the thread of another process. The original question just doesn't make sense. You almost had him, though.
Quote from: devcode on October 24, 2007, 09:06 PM
Quote from: iago on October 24, 2007, 08:42 PM
Quote from: brew on October 24, 2007, 10:51 AM
Quote from: iago on October 24, 2007, 10:34 AM
The functions you need are something like:
FindWindow() to get a handle to the window
GetWindowThreadProcessId() to get the process id (I am doing the names from memory, so I could be wrong on that)
OpenProcess() to get a handle to the process
Somebody can correct me if I'm mistaken.
IIRC, OpenProcess returns a handle to the process, not the thread. Perhaps you were thinking of OpenThread? (that requires a thread ID, and GetThreadID requires a thread handle, what i wanted in the first place) I've found a good way to do this-- calling CreateToolhelp32Snapshot with flags TH32CS_THREAD (I thought at first i was going to have to use a kernel mode api for this one) then call OpenThread. Thanks anyways.
Ah, the original question was worded funny, "Hey, how would i get a handle to the thread of another process?"
I assumed you wanted to get a handle to the process. What I think you wanted to ask was how to get a handle to a thread in another process.
Question was fine and worded properly, else he would have asked "How would i get a handle to another process". You made a mistake and you're justifying it by partly blaming for their wording so, no doesnt work like that unfortunately. Nice try though, better luck next time
lolol. no
Quote from: Warrior on October 25, 2007, 05:28 AM
Quote from: devcode on October 24, 2007, 09:06 PM
Quote from: iago on October 24, 2007, 08:42 PM
Quote from: brew on October 24, 2007, 10:51 AM
Quote from: iago on October 24, 2007, 10:34 AM
The functions you need are something like:
FindWindow() to get a handle to the window
GetWindowThreadProcessId() to get the process id (I am doing the names from memory, so I could be wrong on that)
OpenProcess() to get a handle to the process
Somebody can correct me if I'm mistaken.
IIRC, OpenProcess returns a handle to the process, not the thread. Perhaps you were thinking of OpenThread? (that requires a thread ID, and GetThreadID requires a thread handle, what i wanted in the first place) I've found a good way to do this-- calling CreateToolhelp32Snapshot with flags TH32CS_THREAD (I thought at first i was going to have to use a kernel mode api for this one) then call OpenThread. Thanks anyways.
Ah, the original question was worded funny, "Hey, how would i get a handle to the thread of another process?"
I assumed you wanted to get a handle to the process. What I think you wanted to ask was how to get a handle to a thread in another process.
Question was fine and worded properly, else he would have asked "How would i get a handle to another process". You made a mistake and you're justifying it by partly blaming for their wording so, no doesnt work like that unfortunately. Nice try though, better luck next time
lolol. no
lolol. hi
Quote from: betawarz on October 25, 2007, 12:00 AM
Quote from: devcode on October 24, 2007, 09:06 PMQuestion was fine and worded properly, else he would have asked "How would i get a handle to another process". You made a mistake and you're justifying it by partly blaming for their wording so, no doesnt work like that unfortunately. Nice try though, better luck next time
Uh, nope. Read brew's question, and then hopefully you'll understand iago's thoughts. You don't get a handle to the thread of another process. The original question just doesn't make sense. You almost had him, though.
I know you like iago and all but you can hop off cause he's still not going to give you Windows.Vista.Source.Code-2007-iago. Next.
Quote from: devcode on October 25, 2007, 08:27 AMI know you like iago and all but you can hop off cause he's still not going to give you Windows.Vista.Source.Code-2007-iago. Next.
I C WHAT U DID THAR
Quote from: betawarz on October 25, 2007, 11:05 AM
Quote from: devcode on October 25, 2007, 08:27 AMI know you like iago and all but you can hop off cause he's still not going to give you Windows.Vista.Source.Code-2007-iago. Next.
I C WHAT U DID THAR
OMG I JUST C WHAT I DID THAR
Quote from: betawarz on October 25, 2007, 12:00 AM
[Uh, nope. Read brew's question, and then hopefully you'll understand iago's thoughts. You don't get a handle to the thread of another process. The original question just doesn't make sense. You almost had him, though.
warz is right. I did word it wrong, I ment to say the thread
s' IDs of another process.