I need to find the following string in a binary file. Code (Text): SEGA SEGAKATANA SEGA ENTERPRISES How do I do that using VB6? I've seen methods for text files using "Line Input" and then some other simple stuff, but this is not a text file. Halp plz? cheers
Why use vb6 when you can use the strings tool? My strings has an -o option to get the offset into the file. I'm pretty sure you can pipe the output into vb6; if not, then just write the output to a text file and read it in.
OPEN "WHATEVER" FOR BINARY AS #1 A$="SEGA SEGAKATANA SEGA ENTERPRISES" B$=SPACE$(32) FOR I& = 1 TO LOF(1) GET #1,I&,B$ IF A$=B$ THEN MSGBOX "YAY YOU FOUND THE STRING" EXIT FOR ENDIF NEXT IF I& = LOF(1)+1 THEN MSGBOX "YOU DIDN'T FIND THE STRING D:" CLOSE #1
A Unix program that finds all ASCII strings in a binary file. For example: Code (Text): $ strings /bin/stty | tail -aefg aef:g stdin isn't a terminal TIOCGETD TIOCGWINSZ illegal option -- %s tcsetattr TIOCGWINSZ: %s gfmt1 stdout appears redirected, but stdin is the control descriptor
Yes. You're welcome. Yes. Very slow. A much faster alternative would be this, given that your file isn't too big: OPEN "WHATEVER" FOR BINARY AS #1 A$="SEGA SEGAKATANA SEGA ENTERPRISES" B$=SPACE$(LOF(1)+32) GET #1,,B$ FOR I&=1 TO LOF(1) IF MID$(B$,I&,32)=A$ THEN MSGBOX "YAY YOU FOUND THE STRING" EXIT FOR ENDIF NEXT IF I& = LOF(1)+1 THEN MSGBOX "YOU DIDN'T FIND THE STRING D:" CLOSE #1 Note that you can't combine the two approaches like I once suggested you for another problem, because this time the string you are looking for might be between two blocks if you are particularly unlucky so no -- don't do that. Use either this or the other approach. And yes, I know that adding 32 to the LOF(1) makes the string bigger for no reason. But this gives you a much better FOR in return.
Yeah well the files are ranging from 40MB (if lucky) to 1GB (if unlucky).... :S I'm trying the first solution on a 400MB file right now and I am doing my homework while it's doing that.. Expecting it to be done by then =P EDIT.EXE: I think you can fix the problem by dividing the file in chunks (like 1MB). Then you scan, and the next chunk will start at Current Offset + 1MB - 32 bytes. ??? Profit?
That was my original concern. Oerg came up with a solution that, while not elegant, works. The chunks will overlap by 32 bytes.
EDIT: Shit was all wrong. This works: Dim ding As Long Open Dir1.Path + "\" + File1.FileName For Binary As #1 A$ = "SEGA SEGAKATANA SEGA ENTERPRISES" B$ = Space$(65504) Calculators: parts% = Int((LOF(1) - 65504) / 65504) rest% = (LOF(1) - 65536) Mod 65504 ding = 1 While Not EOF(1) c$ = Space$(65536) Get #1, ding, c$ For I = 1 To Len(c$) - 31 If Mid$(c$, I, 32) = A$ Then r$ = "4DB7 GD-ROM1/1 JUE " Get #1, ding + I + 31, r$ Put #1, , "0799A10" MsgBox "Done patching. Use at own risk! If you have a CRT and the signal is bad, you might damage it!" Close #1 Exit Sub End If Next I ding = ding + 65504 Wend MsgBox "Couldn't find SEGAKATANA identifyer string. Are you sure that this is a dreamcast image?" Close #1 EDIT: Hahaha, this patched a 725MB image in like half a second :D - Thanks guys!
Damn it you're awesome, if only we had people in the PS2 scene who patched games to work with VGA. The only games that work on PS2 VGA are Tekken 4 and 2 built in Linux games. And there's some retail disc which supports like 7 games.
Look at the code, it's just overwriting a string =P Most games have proper VGA init code and stuff but the string doesn't imply it's compatible with it, so the DC displays an error message. The patcher fixes it.