Changeset 489 for tools/wow_patcher/wowpatcher.pas
- Timestamp:
- Sep 8, 2010, 10:10:56 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/wow_patcher/wowpatcher.pas
r474 r489 9 9 Classes, SysUtils, CustApp 10 10 { you can add units after this }; 11 12 const 13 Version = '1.2'; 14 ReleaseDate = '2010-09-08'; 11 15 12 16 type … … 38 42 ErrorMsg: String; 39 43 begin 44 WriteLn('wowpatcher ' + Version + ' ' + ReleaseDate); 40 45 if HasOption('h', 'help') then begin 41 46 WriteHelp; … … 126 131 Position: Integer; 127 132 I: Integer; 133 Shift: Integer; 134 NotValid: Boolean; 128 135 const 129 136 StartSequence: array[0..15] of Integer = ($8D, $4D, $E8, $E8, -1, -1, -1, -1, $5B, $8B, $E5, $5D, $C3, $8D, $49, $00); 130 137 StartSequence2: array[0..15] of Integer = ($88, $1D, -1, -1, -1, -1, $E8, -1, -1, -1, -1, $5B, $8B, $E5, $5D, $C3); 131 138 begin 132 OriginalFile := TFileStream.Create(FileName, fmOpenRead); 133 NewFile := TFileStream.Create(NewFileName, fmCreate); 134 SetLength(Buffer, OriginalFile.Size); 135 OriginalFile.Read(Buffer[0], Length(Buffer)); 136 OriginalFile.Destroy; 137 138 WriteLn; 139 Write('Searching for first sequence '); 140 WriteHexData(StartSequence, 0, Length(StartSequence)); 141 Write('...'); 142 Position := FindSequence(Buffer, StartSequence, 0); 143 if Position <> -1 then begin 144 WriteLn('found at ' + IntToHex(Position, 8)); 145 Inc(Position, Length(StartSequence)); 146 WriteLn('Changing data after sequence'); 147 WriteHexData(Buffer, Position, 16); 148 for I := 0 to 11 do 149 Buffer[Position + I] := Buffer[Position + 12 + (I mod 4)]; 150 WriteLn(' => '); 151 WriteHexData(Buffer, Position, 16); 139 try 140 NewFile := TFileStream.Create(NewFileName, fmCreate); 141 try 142 OriginalFile := TFileStream.Create(FileName, fmOpenRead); 143 SetLength(Buffer, OriginalFile.Size); 144 OriginalFile.Read(Buffer[0], Length(Buffer)); 145 finally 146 OriginalFile.Free; 147 end; 148 152 149 WriteLn; 153 end else WriteLn('not found'); 154 155 WriteLn; 156 Write('Searching for second sequence '); 157 WriteHexData(StartSequence2, 0, Length(StartSequence2)); 158 Write('...'); 159 Position := FindSequence(Buffer, StartSequence2); 160 if Position <> -1 then begin 161 WriteLn('found at ' + IntToHex(Position, 8)); 162 Inc(Position, Length(StartSequence2)); 163 WriteLn('Changing data after sequence'); 164 WriteHexData(Buffer, Position, 16); 165 for I := 0 to 11 do 166 Buffer[Position + I] := Buffer[Position + 12 + (I mod 4)]; 167 WriteLn(' => '); 168 WriteHexData(Buffer, Position, 16); 150 Write('Searching for first sequence '); 151 WriteHexData(StartSequence, 0, Length(StartSequence)); 152 Write('...'); 153 Position := FindSequence(Buffer, StartSequence, 0); 154 if Position <> -1 then begin 155 WriteLn('found at ' + IntToHex(Position, 8)); 156 Inc(Position, Length(StartSequence)); 157 if FindSequence(Buffer, StartSequence, Position) <> -1 then 158 WriteLn('Multiple occurence found - ambiguous') 159 else begin 160 Shift := 0; 161 repeat 162 NotValid := False; 163 for I := 0 to 3 do 164 if Buffer[Position + Shift + 3 + I * 4] <> 0 then NotValid := True; 165 if NotValid then Inc(Shift); 166 if Shift > 100 then begin 167 WriteLn('No valid data found after sequence'); 168 Exit; 169 end; 170 until not NotValid; 171 if Shift > 0 then WriteLn('Data shift after sequence: ' + IntToStr(Shift)); 172 Position := Position + Shift; 173 174 WriteLn('Changing data after sequence'); 175 WriteHexData(Buffer, Position, 16); 176 for I := 0 to 11 do 177 Buffer[Position + I] := Buffer[Position + 12 + (I mod 4)]; 178 WriteLn(' => '); 179 WriteHexData(Buffer, Position, 16); 180 end; 181 WriteLn; 182 end else WriteLn('not found'); 183 169 184 WriteLn; 170 end else WriteLn('not found'); 171 172 NewFile.WriteBuffer(Buffer[0], Length(Buffer)); 173 NewFile.Destroy; 185 Write('Searching for second sequence '); 186 WriteHexData(StartSequence2, 0, Length(StartSequence2)); 187 Write('...'); 188 Position := FindSequence(Buffer, StartSequence2); 189 if Position <> -1 then begin 190 WriteLn('found at ' + IntToHex(Position, 8)); 191 Inc(Position, Length(StartSequence2)); 192 if FindSequence(Buffer, StartSequence2, Position) <> -1 then begin 193 WriteLn('Multiple occurence found - ambiguous') 194 end else begin 195 Shift := 0; 196 repeat 197 NotValid := False; 198 for I := 0 to 3 do 199 if Buffer[Position + Shift + 3 + I * 4] <> 0 then NotValid := True; 200 if NotValid then Inc(Shift); 201 if Shift > 100 then begin 202 WriteLn('No valid data found after sequence'); 203 Exit; 204 end; 205 until not NotValid; 206 if Shift > 0 then WriteLn('Data shift after sequence: ' + IntToStr(Shift)); 207 Position := Position + Shift; 208 209 WriteLn('Changing data after sequence'); 210 WriteHexData(Buffer, Position, 16); 211 for I := 0 to 11 do 212 Buffer[Position + I] := Buffer[Position + 12 + (I mod 4)]; 213 WriteLn(' => '); 214 WriteHexData(Buffer, Position, 16); 215 end; 216 WriteLn; 217 end else WriteLn('not found'); 218 219 NewFile.WriteBuffer(Buffer[0], Length(Buffer)); 220 finally 221 NewFile.Free; 222 end; 174 223 end; 175 224
Note:
See TracChangeset
for help on using the changeset viewer.