|
The first code works, however I need to be able to read contents of multiple files from a particular directory.
Start simple and build from there I figure. Doing something wrong somewhere, as the 2nd code only brings up the dos window without any data.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace readtest
{
class Program
{
static void Main(string[] args)
{
StreamReader sr = new StreamReader("C:\\Users\\Random.txt");
string str = sr.ReadLine();
string[] words = str.Split('|');
foreach (string word in words)
{
Console.WriteLine(word);
} Console.ReadKey();
}
}
}
This is the one I need to have working. I must be structuring something wrong. I've tried different ways, but no luck.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
string[] files = Directory.GetFiles("C:\\Users", ".txt");
foreach (string file in files)
{
StreamReader sr = new StreamReader(file);
string str = sr.ReadLine();
{
Console.WriteLine(file);
}
} Console.ReadKey();
}
}
}
|
|
|
|
|
Member 8363084 wrote: string[] files = Directory.GetFiles("C:\\Users", ".txt");
you have to use * here as
string[] files = Directory.GetFiles("C:\\Users\\", "*.txt");
regards
|
|
|
|
|
try
string[] files = Directory.GetFiles("C:\\Users\\", "*.txt");
Although it may read a bit better with an @ sign
string[] files = Directory.GetFiles(@"C:\Users\", "*.txt");
"You get that on the big jobs."
|
|
|
|
|
To cut to the chase, our current connection string is:
Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties='Excel 12.0 Xml;HDR=YES;'
We really do not have the option of pushing a TypeGuessRows registry change to all users in order to force Excel to scan the whole column.
Can TypeGuessRows be given as an extended property to the ACE Provider?
Note: I know this isn't necessarily a C# specific question, but I'm writing in C# using an OleDbCommand, using the connectionString above.
"I need build Skynet. Plz send code"
|
|
|
|
|
There's no way to force TypeGuessRows in the connection string to a different value. I think your only option is to append "IMEX=1" to the connection string, which forces Excel to read all column data as text only. You'll then have to parse out out values from the strings returned.
|
|
|
|
|
btw, MS advised that the following should be correct:
Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties='Excel 12.0 Xml;HDR=YES;Imex=1;ImportMixedTypes=Text;TypeGuessRows=0;
"I need build Skynet. Plz send code"
|
|
|
|
|
Update 1
CreateFile hooking now works, but only when I suspend the state of the program when it is started, hook the process and then resume the process. I need to be able to do this when a process is opened without interacting with my program. (Meaning I am not able to start it suspended, I need a way to hook the process start or something.) It has been suggested to use Drivers... I'm all ears!
Next issue, when I hook an already running process, I need to be able to determine the file handle linked to gw.dat, and reopen the file to that same handle using ReOpenFile and new share peramaters. Are there any ideas on how to do this? I am not familiar with doing something like this, much less in an unmanaged environment....
Related Questions:
WIN32 API override (Specifically CreateFile) in C# [Solved and very helpful]
How to tell what method opens a file [Solved and not helpful]
Suspend specific process on launch C# [Not Solved, hoping for easier answer...]
Run code inside process with EasyHook
Change a handle in unmanaged code without pre-existing knowledge of process internals [From injected DLL]
Original
Note: I figured I would post this here to get input, and in case anyone tries something similar in the future.
Before you read any further please understand that I do not intend to go any farther then allowing the client to be run more then once. The only advantage will be the same as having two computers next to each other.
I am using C# with EasyHook.
Background: Guild Wars is an MMORPG, for the most part there are mainly only two files. gw.exe which is less then a MB is executed, opens gw.dat (With exclusive rights), checks for updates, loads the rest of the game from gw.dat. gw.dat just holds everything else.
gw.exe makes sure it is not running already when it first starts, and if it is it will just force the prior process to the foreground. If you remove the mutex you cannot properly open a second gw.exe because the first has exclusive rights to the one and only gw.dat.
Yes, it is possible to remove the mutex and run multiple gw.exe processes pointing to different gw.dat files with some registry changes but the gw.dat gets over 4GB and it is just annoying.
Possible Solution: Trough looking around I have put together a DLL, and can successfully inject it into the gw.exe process using EasyHook. I can hook methods of other DLL's, and can interface with the injecting program. Originally it had been suggested I hook CreateFileW and change the call so it does not force exclusivity to the file. It turns out that either I hook the process too late for CreateFileW is not the function used to connect to the file. (Figured this out)
It was also suggested that I could call ReOpenFileW to change current handles to gw.dat to share mode. I can't seem to be able to run anything that isn't inside a hook so I can't call ReOpenFileW. (Though I can hook it)
Intended Result: Basically, what I intend to achieve is injecting a DLL into gw.exe, forcing it to remove a file lock, and remove the mutex (mutex can be done externally but I figure while I'm in there why not?)
Are there any ideas? Alternative solutions?
I have been working on this easyhook solution for a few days now, but in all honesty if it is doomed, or there is an easier way to do this I am all ears!
Quick Note: While doing something like this is against the EULA of the game, there has never been a problem with it in the past and there have been no bannings for this specific type of modification!
Also, if you want to try your hand at doing this or want a first hand look at what is being done by gw.exe (I tried to understand the assembly but I never learned that art....) The gw.exe can be downloaded here, and can be run without an account. You just can't play the game. If needed I can upload my current source! I'll have to clean it up a bit though....
modified 9-Nov-11 22:19pm.
|
|
|
|
|
How do you start/hook? Do you start the gw.exe process in a suspended state?
|
|
|
|
|
I hand't thought of doing that actually... I was intending to hook every process run automatically without needing to start the process with my code at all. Though I suppose suspended state would just make sense till I get things running....
At the moment I detect process start by watching for it with ManagementEventWatcher like so:
string queryString =
"SELECT TargetInstance" +
" FROM __InstanceCreationEvent " +
"WITHIN " + 1 + " " +
" WHERE TargetInstance ISA 'Win32_Process' " +
" AND TargetInstance.Name = '" + processName + "'";
string scope = @"\\.\root\CIMV2";
watcher.EventArrived += ProcessStarted;
watcher.Start();
I then hook using EasyHook:
Config.Register(
"A FileMon like demo application.",
"FileMon.exe",
"FileMonInject.dll");
RemoteHooking.IpcCreateServer<FileMonInterface>(ref ChannelName, WellKnownObjectMode.SingleCall);
RemoteHooking.Inject(
TargetPID,
"FileMonInject.dll",
"FileMonInject.dll",
ChannelName);
modified 8-Nov-11 15:01pm.
|
|
|
|
|
The hooking code might run too late then, or maybe it doesn't and there's an other problem, but I think it's a good theory
|
|
|
|
|
Is there a quicker way to hook a process or detect it's initialization? Such as hooking the process creator itself? Not sure what that would be on a global scale....
|
|
|
|
|
Is that even possible with user mode hooks? Well in any case I wouldn't go that far..
I know of no quicker ways, is starting the process from your program unacceptable?
|
|
|
|
|
Unfortunately for the end result it is.
The final product will basically sit there waiting for a user to run the game from anywhere using any method, hook it, remove the limitations for multi run, and wait for the next. That way there is no setup needed what so ever from the users, they don't need to mess around with shortcuts and command line arguments will run just fine. It will also allow things such as TexMod (Third party tool that modifies textures in memory, but requires the game to be run through it)
|
|
|
|
|
Ok that complicated matters. There's an article on cp that explain how to hook process creation[^] (not the same way you're hooking, but probably contains something useful), it's a bit heavy handed but could be worth a try
|
|
|
|
|
I saw that earlier.... I'm not too sturdy with C, but I suppose I can give it a shot tomorrow.
The only problem I can see with that is that I need to be able to inject into the process, and I can't see an obvious way to do so given that method....
|
|
|
|
|
I don't know either, but there's something I just thought about - what if you use that technique to hook CreateFile and OR in the sharing bits if the file being opened is gw.dat?
|
|
|
|
|
gw.dat is either not loaded using CreateFile, or it is being loaded so quickly that the current method can't even see it.
I can hook before WindowBlinds DLL's get in there, but not before the initial call to gw.dat... Which makes me think that CreateFile isn't being used, though I could be wrong.
|
|
|
|
|
Ok that's weird.. that other way to hook would definitely be on time if it's being opened with CreateFile, but if CreateFile isn't even used then I have no clue what's going on there
|
|
|
|
|
Ummm...Why try and piss on a spark plug when you could just run multiple virtual machines, each with its own copy of the game running?
|
|
|
|
|
Easy, the final product is going to be released (for free of course).
I can't release virtual machines, and they would take longer to set up then the current solutions. I am going for simplicity.
|
|
|
|
|
I wouldn't come here and ask for advice on hacking a MMORPG client, even if you have noble intent (which you didn't specify, so we can't assume either way.) Other people here probably play the game and don't want people interfering with whatever integrity the game still has.
That's kind of like going to an auto mechanics' forum and asking how to circumvent your car's ODB-II system so your car would pass inspection without repairing some problem, or going to a gun enthusiasts' forum and asking how you can manufacture parts that are illegal in your area.
No hate from me here. Just saying you probably shouldn't do this, nor should you ask here. Why run multiple instances, anyway? You can only control one instance of a game at a time.
|
|
|
|
|
While I would agree with you if I were doing anything that would gain an upper hand, in this case I do have to disagree.
There has never been a moral dillema with the end result I am trying to achieve. It can easily be replicated by having two computers next to each other.
The only part of the EULA that is being bent is not exercised against this type of third party program. Mind you that doesn't give users the go ahead, but there have been many non automated approaches that have been released without issue for years (Non automated meaning you have to load the game through the programs themselves)
There are also legit reasons for this, such as AFKing certain events with multiple accounts, trading between accounts without having to trust a middle man, and you can theoretically multibox.
modified 8-Nov-11 15:35pm.
|
|
|
|
|
I don't see anything in that which isn't just a rationalization.
|
|
|
|
|
Then I have to ask, what could I gain from having more then one client open at a time? I have five accounts, I like to AFK them for events and I trade between them.
My wife plays the game but is horrible at picking what items to keep from a farming run so she likes me to do it for her. Why close my current game to do the same thing with another account when I can have two open at once? I like to run two of those accounts in a way that they are in my party just sitting there for quests.
Again, all I can do with this modification is exactly what I can do with the four computers in the house (minus one account obviously), but that is a lot of extra electricity, room, and other members of the family like to use the computers.
Anyway, this has been done many times before, I'm just making it more convenient and easier for the end user. And I'm learning how to do something new in a programming language I love. Sure I could use things already made but why not improve it instead of settling?
|
|
|
|
|
Again all of that is just your attempt to rationalize your actions.
Seems rather pointless to defend it by trying to come up with reasons why it 'should' be ok.
Your responses indicate that you know that you are violating something but then you attempt to justify it by suggesting that it doesn't actually hurt anything. There might be merit to the later but it doesn't eliminate the former.
|
|
|
|