Encrypting and Decrypting

talk and review codes here

Moderators: Q-dad~TAG, EXP STAFF, Moderator

Encrypting and Decrypting

Postby Fred » 06-02-2006 04:26 PM

I know we have these tools already, but I'm curious. Where do you even begin to learn about the encryption\decryption coding ?

I've coded a little with VB and C++ - and toyed with hex editing, so I'm not a complete noob, but this was not a topic covered in class.
Tons of Software
No Talent
Fred
MOD Scientist
 
Posts: 113
Joined: 06-29-2004 05:41 AM

Postby Q-dad~TAG » 06-02-2006 06:49 PM

Fred wrote:I know we have these tools already, but I'm curious. Where do you even begin to learn about the encryption\decryption coding?

Hi Fred,

A few years ago DV & MH helped us enc/dec items.def for DF2 each time we wanted to test some new stuff for our (still unreleased, sigh) TXP2 mod. However, that turned out to be a slow process, so we decided to try figuring out how to make our own enc/dec tool. Here's roughly the method we used...:

1.) Establish what exactly goes on when the encrypted items.def file is being loaded into memory (and thus being decrypted) by either the df2.exe file or the df2med.exe file. I found it easier to work with the df2med.exe file, and I stripped the df2.pff of everything which didn't need to be there in order for the df2med to load it, i.e. all I left in there was the items.def file and one or two more files)

2.) To accomplish 1.) one would need a debugger tool, for example the old freeware OllyDbg. When the items.def is being loaded, you'll need to look out for something acting as a decryption key, and also try to figure out what kind of algorithms are being used during the decryption process. It could include adding some numbers together, bit shifting, X-OR'ing, etc, etc... The same thing goes for the encryption process, but it's basically an inverted version of the decryption process.

3. While doing 1.) and 2.) we simultaneously started coding an enc/dec tool in Delphi, trying out the different stuff we figured out with OllyDbg. The core of the enc/dec algorithms I added as ASM code inside Delphi. Had to learn Delphi as well, lol.

It took us a few weeks (at least), since none of us had done anything similar before. We're stunt coders, I guess... :cool:
TXP (Terrain Xpansion Pack) for DF2: http://txp.df2.org/

Image
User avatar
Q-dad~TAG
Senior Member
 
Posts: 269
Joined: 03-29-2004 01:00 AM

Cool

Postby Fred » 06-02-2006 08:13 PM

Thanks Q-dad. I had no where to even start. Delphi, huh ? I'm gonna check into that this weekend.

There was another I was interested in looking at. Before chancellor dropped his site, he was talking about it - small, but powerful. Can't remember what it was called. VBLite or something.
Tons of Software
No Talent
Fred
MOD Scientist
 
Posts: 113
Joined: 06-29-2004 05:41 AM

Postby DR.EVIL~TAG » 06-02-2006 08:44 PM

For your gaming textures and downloads. Now hosting over 5000 game textures and more uploaded every night. Click the sig.
Image
DR.EVIL~TAG
Mod Depot Staff
 
Posts: 427
Joined: 03-31-2004 03:31 PM

Thanks

Postby Fred » 06-02-2006 09:17 PM

You have to register to use ? I'm not going to install until tomorrow. I did some checking after reading the reply - and it appears that Personal free - but minus a few extras. I registered with borland when getting C++ for school. Maybe that will work.
Tons of Software
No Talent
Fred
MOD Scientist
 
Posts: 113
Joined: 06-29-2004 05:41 AM

Postby DR.EVIL~TAG » 06-02-2006 09:35 PM

Rgr, the Personal Edition is a free download, They offered out a few years back , Not to many sites still carry it, The newer version you have to pay for.

You need to register with borland under the personal edition and they will send you the activation key/license for it.

Alot of the newer addons will work on Delphi 6 ,

I still use it
For your gaming textures and downloads. Now hosting over 5000 game textures and more uploaded every night. Click the sig.
Image
DR.EVIL~TAG
Mod Depot Staff
 
Posts: 427
Joined: 03-31-2004 03:31 PM

Postby A.bullet » 06-02-2006 09:35 PM

unit DUnit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, FileCtrl;

type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
drive : char;
Filename, OutFileName, Infile : String;
FilePath : String;
FileContents : Array of Char;
PMemory : PByte;
FileSizeU : LongInt;
saveDialog : TSaveDialog;

procedure scrEncrypt(FileName: String);
procedure scrDecrypt(FileName: String);
procedure scrReadFile(FileName: String);
procedure scrWriteFile(FileName: String);

implementation

{$R *.dfm}


procedure TForm1.FormCreate(Sender: TObject);
begin

Form1.Visible := False;

inFile := ParamStr(1);

//ShowMessage('Param 1 : ' + inFile);

ProcessPath(inFile, drive, FilePath, FileName);

// Create the save dialog object - assign to our save dialog variable
saveDialog := TSaveDialog.Create(Application);

// Give the dialog a title
saveDialog.Title := 'Save As';

// Set up the starting directory to be the current one
saveDialog.InitialDir := FilePath;
saveDialog.FileName := FileName;

// Allow only .txt and .doc file types to be saved
saveDialog.Filter := 'ADM File|*.adm|AIP file|*.aip|CIN file|*.cin|DEF File|*.def|LDO file|*.ldo|PTL file|*.ptl|All files|*.*';

// Set the default extension
saveDialog.DefaultExt := 'def';

// Select text files as the starting filter type
saveDialog.FilterIndex := 4;

// Display the open file dialog
if saveDialog.Execute then
begin
//ShowMessage('File : '+saveDialog.FileName);

FileName := saveDialog.FileName;

scrReadFile(InFile);
scrDecrypt(FileName);
scrWriteFile(FileName);
end;

// saveDialog.Free;
Application.Terminate;

end;


procedure scrEncrypt(FileName: String);
begin

pMemory := pbyte(FileContents);

asm
mov esi,pMemory
mov edi,2A5A8EADh
mov ecx,FileSizeU
add ecx,04h
@loc_004D74CB:
mov eax, edi
rol eax, 0Bh
add eax, edi
rol eax, 04h
xor eax, 00000001h
mov edi, eax
mov bl, byte ptr [esi]
xor bl, al
mov byte ptr [esi], bl
inc esi
dec ecx
jne @loc_004D74CB
mov eax,FileSizeU
add eax,4h
mov edi,pMemory
add edi,FileSizeU
sub edi,01h
mov ecx,FileSizeU
shr ecx,1
mov esi,pMemory
@loc_004D74B5:
mov al, byte ptr [esi]
mov bl, byte ptr [edi]
mov byte ptr [esi], bl
mov byte ptr [edi], al
inc esi
dec edi
dec ecx
jne @loc_004D74B5
end;


end;

procedure scrDecrypt(FileName: String);
begin

pMemory := pbyte(FileContents);

asm
mov eax,pMemory
cmp dword ptr [eax],01524353h
je @srcdec
jmp @exit
@srcdec:
mov eax,FileSizeU
sub eax,4h
mov edi,pMemory
add edi,FileSizeU
sub edi,01h
mov ecx,FileSizeU
shr ecx,1
sub ecx,2
mov esi,pMemory
add esi,04h
@loc_004D74B5:
mov al, byte ptr [esi]
mov bl, byte ptr [edi]
mov byte ptr [esi], bl
mov byte ptr [edi], al
inc esi
dec edi
dec ecx
jne @loc_004D74B5
mov esi,pMemory
add esi,04h
mov edi,2A5A8EADh
mov ecx,FileSizeU
sub ecx,04h
@loc_004D74CB:
mov eax, edi
rol eax, 0Bh
add eax, edi
rol eax, 04h
xor eax, 00000001h
mov edi, eax
mov bl, byte ptr [esi]
xor bl, al
mov byte ptr [esi], bl
inc esi
dec ecx
jne @loc_004D74CB
add pMemory,4
sub FileSizeU,4
@exit:
end;

end;

procedure scrReadFile(FileName: String);
var
in_stream: TStream;
begin

in_stream := TFileStream.Create( FileName, fmOpenRead or fmShareDenyNone );

try

in_stream.Position := 0;
FileSizeU := in_stream.Size;

SetLength(FileContents, FileSizeU);
in_stream.Read(FileContents[0], FileSizeU);

finally
in_stream.Free;
end;

end;

procedure scrWriteFile(FileName: String);
var
out_stream: TStream;
header : String;
begin

out_stream := TFileStream.Create( Filename, fmCreate or fmShareExclusive );

try

//header := 'SCR';

out_stream.Position := 0;
//out_Stream.Write(header[1],4);
out_stream.Write(FileContents[4], FileSizeU);

finally
out_stream.Free;
end;

end;

end.
Admin Mod Depot
Owner / Admin DFBarracks.com
User avatar
A.bullet
Admin
 
Posts: 107
Joined: 02-09-2004 02:37 AM

Postby A.bullet » 06-02-2006 09:39 PM

Theres the encryption decryption for BHD..


Its a delphi program that uses the Assembly right from the med / game..

thats for BHD.. its the same for JO .. but it might have a different key it uses.. thats the hex number in the beginning of the decrypt / encrypt algorithm..

I know the beta used babyface as a key.. LOL.. I think JO is the same as BHD.. but my fuzzy memory cant come up with a proper answer.. anyhow... stick it in delphi and compile.. and give it a shot on a JO file.. if it dont work shout and I will do more digging..

Anyhow.. thats how I did it..
Admin Mod Depot
Owner / Admin DFBarracks.com
User avatar
A.bullet
Admin
 
Posts: 107
Joined: 02-09-2004 02:37 AM

Postby A.bullet » 06-02-2006 09:40 PM

oh by the way.. I use that as a program I stuck in my send to directory.. then I just send SCR encrypted files to that program for encryption/decryption to the current directory..
Admin Mod Depot
Owner / Admin DFBarracks.com
User avatar
A.bullet
Admin
 
Posts: 107
Joined: 02-09-2004 02:37 AM

Postby A.bullet » 06-02-2006 09:44 PM

oh hell.. might as well give the exe's out..

Def Decrypt/Encrypt

Add these to your
C:/Documents and Settings/Username /SendTo
Directory - then use right click send to - BHD Decryption / Encryption to encrypt / decrypt files right from my computer / windows explorer
Admin Mod Depot
Owner / Admin DFBarracks.com
User avatar
A.bullet
Admin
 
Posts: 107
Joined: 02-09-2004 02:37 AM

Postby Fred » 06-02-2006 10:08 PM

Come back to find out if I'm gonna have to register Delphi and...


WHAT !!??

Now I HAVE to study it...to understand what you just posted..lol. ( though some little bit of it I already do )

Whew !!.. what a head start..

Thanks Abullet. Thanks Evil.

-------------------------------------------------------

As I look at this, it appears that you can run asm inside of Delphi -like PHP inside HTML ?
Tons of Software
No Talent
Fred
MOD Scientist
 
Posts: 113
Joined: 06-29-2004 05:41 AM

Postby Q-dad~TAG » 06-03-2006 04:19 AM

Fred wrote:Before chancellor dropped his site, he was talking about it - small, but powerful. Can't remember what it was called. VBLite or something.

I believe he used something called PowerBASIC...: http://www.powerbasic.com/

A.bullet wrote:Anyhow.. thats how I did it..

Hehe, you've just robbed him of the rewarding process of learning how to use a debugger... :D

Fred wrote:As I look at this, it appears that you can run asm inside of Delphi -like PHP inside HTML ?

Yes, it supports a variety of internal ASM functions.
TXP (Terrain Xpansion Pack) for DF2: http://txp.df2.org/

Image
User avatar
Q-dad~TAG
Senior Member
 
Posts: 269
Joined: 03-29-2004 01:00 AM

Postby DV- » 06-03-2006 02:36 PM

I do it like Q-dad says in his first post :)
DV-
Senior Member
 
Posts: 151
Joined: 03-12-2004 02:08 PM

Postby Fred » 06-03-2006 04:47 PM

I tried building and compiling Abullet's code, changing the key to the one needed for C4 ( thanks to DV's scrkeys.ini ), but had little success. I didn't get the other file that that Abullet had, just the executable and some other build files. However, all of this is without reading the manual and some PDF instructions I downloaded - so I'm sure I'm missing something.

I downloaded the dissassembler/debugger you suggested Q-dad - and am going to look at it too while attaching to the MED. My assembly knowledge is weak - so, I have a feeling I'll be plugging away at this for some time, in between modeling some new buildings, studying PHP, Java and Flash.

We need a MOD for life - one with 48 hour days and 400 year life spans. There is just too much to learn and do.
Tons of Software
No Talent
Fred
MOD Scientist
 
Posts: 113
Joined: 06-29-2004 05:41 AM

Postby =BT=Bloodhawk1 » 03-19-2007 09:02 PM

Maybe this is how the glb was debuged :)
=BT=Bloodhawk1
Senior Member
 
Posts: 155
Joined: 04-15-2006 01:16 PM

Next

Return to Coders Hell

Who is online

Users browsing this forum: No registered users and 1 guest

cron