1

I am currently working on a project where i can encrypt and decrypt files. I am developing it in Java.

This is how it works (simplified):

  1. First I read the file and convert it to a byte array
  2. Then I encrypt the byte array and write it back to a file

When I want to run the encrypted file, I do the opposite, so like this:

  1. I read encrypted file and convert it to byte array
  2. Then I decrypt the byte array and write it back to a file.

So the file is converted back to its original form.

My problem is, I do not want to write the decrypted byte array as a file to the disk.

Is there a way to do this? I want to run the decrypted byte array directly in memory. By "running" it, I mean executing it, because it is a Win32 executable crypter.

Thanks in advance, Onur

erickson
  • 265,237
  • 58
  • 395
  • 493
  • Hi, I hate to bring up a dead topic but if you could share the code you described (especially the conversion to the byte[]) you'd save me a great deal of time :) please share. – Shark Aug 21 '12 at 10:27

3 Answers3

1

I'd say that your options are limited here, because you are dependent on Windows starting the process. Java, being cross-platform, probably doesn't have the ability to hook into Windows in the way you want.

Straying outside the realms of pure Java, you could create a ramdisk and write the EXE to the Ramdisk, or perhaps bridge across to .NET, as described in this answer (and question links inside that answer).

Community
  • 1
  • 1
Gnat
  • 2,861
  • 1
  • 21
  • 30
  • Does Windows allow you to execute any old chunk of bytes that you wrote to RAM? If so, that seems like a gaping security hole. – Mike Baranczak Dec 08 '11 at 14:45
0

Maybe Java NIO framework will suit you. Look at ByteBuffer and FileChannel

korifey
  • 3,379
  • 17
  • 17
0

I saw the example in c#, this is exactly what i want, but mixing 2 languages is not on option for this project.

I've heard about JNA library that does some win32 native stuff. Maybe i should look at it.

Thank you all for your help, but i still hope someone will post my solution here.

Onur