Hi All,
I am currently developing an application that reads data from PC's Memory. It is working but the output is something like this:
(Please see attached..)
the output is unreadable, it contains a squares,slashes,sharp signs,letters, numbers and etc.
what format is this?is this a binary format?
How could i print it in a readable or string format?
Please help,
Thanks in advance,
MARK TAN
11 20959
Are they in ASCII format?
You can convert the byte array into String in Java.
Check the various string constructors in this link.
This may help you.
Regards
Dheeraj Joshi
Hi Dheeraj Joshi,
I have no idea what are their format,how could i know it?
by the way, i'll gonna check the link you gave..
Thanks a lot.
Mark Tan
I can not see the attachment clearly. Can you post the code here?
Regards
Dheeraj Joshi
here is the output :
run:
Process Handler of Yahoo! Messenger : 66892
Process ID of Yahoo! Messenger : 4252
hProcess : native@0x278
The operation completed successfully.
DATA : �����
HTML can not display it properly on browsers..
and here is the codes that i used for getting data from memory:
public String getMemoryData(int ProcessId, int bufferSize, int offset, Pointer hProcess){
IntByReference baseAddress = new IntByReference();
baseAddress.setValue(offset);
Memory outputBuffer = new Memory(bufferSize);
boolean success = kernel32.ReadProcessMemory(hProcess, offset, outputBuffer, bufferSize, null);
byte[] bufferBytes = outputBuffer.getByteArray(0, bufferSize);
return new String(bufferBytes);
}
All data is binary. ASCII is just a way of interpreting 8 bits (technically 7) of data at a time. ASCII also contains unprintable characters. Hence the weird characters you're seeing. It's because it's applying ASCII encoding and the data just so happens to map to unprintable characters in the ASCII set.
A common method of representing data is to convert all the bytes into hex representation. This doesn't tell you what that data is but you can make some educated guesses. For example, if it's 64 bits long, it could be a double or an 8 character ASCII encoded string or a 2-8 character UTF-8 encoded string.
oh I see.. I'll try to develop a method that will convert bytes into hex...thanks!
Something like this should do the trick for you buddy... -
public class BytesToHex {
-
-
private byte[] inbytes;
-
private String hexString="";
-
-
public BytesToHex(byte[] inbytes){
-
this.inbytes = inbytes;
-
}
-
-
public String toHex() {
-
-
String subString;
-
int i;
-
for (byte b: inbytes){
-
subString ="";
-
i = (int)b & 0xff ;
-
subString = Integer.toHexString(i);
-
if (subString.length()==1){
-
subString = "0" +subString;
-
}
-
this.hexString += subString + " ";
-
}
-
-
return hexString;
-
}
-
-
}
Thanks sir, this is a good help!
Hi darksteel21,
Did you got any solution on your query. I am getting same issue like unreadable string.
Instead of converting the bytes to hexadecimal yourself, you can just use: - System.out.printf("%02X", byte);
or in older Java versions: - System.out.print(String.format("%02X", byte))
Try This Code -
import java.io.*;
-
import java.nio.channels.*;
-
import javax.xml.bind.DatatypeConverter;
-
-
public class EncodeDecode {
-
public static void main(String[] args) throws Exception {
-
File file = new File("/bin/ls");
-
byte[] bytes = loadFile(file, new ByteArrayOutputStream()).toByteArray();
-
String encoded = DatatypeConverter.printBase64Binary(bytes);
-
System.out.println(encoded);
-
byte[] decoded = DatatypeConverter.parseBase64Binary(encoded);
-
// check
-
for (int i = 0; i < bytes.length; i++) {
-
assert bytes[i] == decoded[i];
-
}
-
}
-
-
private static <T extends OutputStream> T loadFile(File file, T out)
-
throws IOException {
-
FileChannel in = new FileInputStream(file).getChannel();
-
try {
-
assert in.size() == in.transferTo(0, in.size(), Channels.newChannel(out));
-
return out;
-
} finally {
-
in.close();
-
}
-
}
-
}
-
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Dan Stromberg |
last post by:
I've written up a page about how to convert native binary data to
another platform's native binary data, as I did some fortran data
conversions for a client.
The programs and documentation are...
|
by: geskerrett |
last post by:
I am hoping someone can help me solve a bit of a puzzle.
We are working on a data file reader and extraction tool for an old
MS-DOS accounting system dating back to the mid 80's.
In the data...
|
by: Dan |
last post by:
To all the gurus out there. I am writing a tool that
receives binary data from a network device. The data
arrives in a standard format which the vendor has
documented, e.g. byte 0 is the format...
|
by: DBuss |
last post by:
I'm trying to convert a binary data feed into something more friendly. Some of the data is Int (and extracts successfully), but some is Double and doesn't. The below line of code gives harsh...
|
by: krupalreddy |
last post by:
i have a problem with date
i have two dates. one is in Date type and the other one is in String type.
i need to compare these two dates.
for this i try to convert date which is in String type to...
|
by: Schmacker |
last post by:
Hi there,
I'm trying to teach myself some things about random file I/O with binary, and have come across a task that I am unsure I know how to approach.
Currently I write out a bunch of...
|
by: larry |
last post by:
Ok I'm a Python noob, been doing OK so far, working on a data
conversion program and want to create some character image files from
an 8-bit ROM file.
Creating the image I've got down, I open...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
| |