Binary files in Python, code snippet in Java to Python

I'm trying to get data out of a game file (ITM/Baldurs Gate http://iesdp.gibberlings3.net/ieformats/itm_v1.htm). Some of variables can't be read directly (like dword) (won't show the data it should).
A java based NearInfinity converts binary dword data in this way:
public static int convertInt(byte buffer[], int offset)
int value = 0;
for (int i = 3; i >= 0; i--)
value = (value << 8) | (buffer[offset + i] & 0xFF);
return value;
Now, how Python code would look like? I've checked binascii module with no luck.

I have
plik = open('bow08.itm', 'rb')
try:
tekst = plik.read()
finally:
plik.close()
# char array - works
print tekst[0x0004:0x0004+4]
# resref - works
print tekst[0x003a:0x003a+8]
#dword
print tekst[0x004c:0x004c+4]
and the dword (and few other variables) won't show anything (will output binary something), the java snippet in my first post from NearInfinity converts that binary code into a normal data

Similar Messages

  • Import binary file in cvs repository through java cvs import command

    hi ,
    I am using netbean api for cvs command.I am having the same problem that i am not able to open binary file after importing in cvs repository.
    I want to import a directory which contain both text and binary file.
    can you please hel me out to how to import a directory which contain binary files.
    MY CODES
    ImportCommand command = new ImportCommand();
    command.setModule(module);
    command.setLogMessage(comment);
    command.setReleaseTag(releaseTag);
    command.setImportDirectory(path);
    client.setLocalPath(path);
    command.setVendorTag(vendorTag);
    Regards
    ruchira

    Please don't cross post
    http://forum.java.sun.com/thread.jspa?messageID=9455793

  • How to handle binary file at the time of import in javacvs

    hi ,
    I am using netbean api for cvs command.I am having the same problem that i am not able to open binary file after importing in cvs repository.
    I want to import a directory which contain both text and binary file.
    can you please hel me out to how to import a directory which contain binary files.
    MY CODES
    ImportCommand command = new ImportCommand();
    Map wrapperMap = new HashMap();
    String filenamePattern="*.ppt";
    KeywordSubstitutionOptions keywordSubstitutionOptions;
    Object b= KeywordSubstitutionOptions.BINARY;
    wrapperMap.put(new SimpleStringPattern(filenamePattern),b);
    command.addWrapper(filenamePattern,org.netbeans.lib.cvsclient.command.KeywordSubstitutionOptions.BINARY);
    command.setWrappers(wrapperMap);
    command.setModule(module);
    command.setLogMessage(comment);
    command.setReleaseTag(releaseTag);
    command.setImportDirectory(path);
    client.setLocalPath(path);
    command.setVendorTag(vendorTag);
    result = client.executeCommand(command, globalOptions);
    Regards
    ruchira

    Please don't cross post.
    http://forum.java.sun.com/thread.jspa?threadID=5127696&tstart=0

  • Read Binary File, Help me! Thanks!

    I want to read a binary file and tried several times,
    but failed, who can give me an example?
    Thank you !

    Thank you very much! my codes are listed below
    i want to read a binary file and convert to ASCII.
    import java.io.*;
    public class FileInputDemo
    public static void main(String args[])
    if (args.length == 1)
    try
    FileInputStream fstream = new FileInputStream(args[0]);
    DataInputStream in = new DataInputStream(fstream);
    while (in.available() != 0)
    System.out.println(in.readLine());
    in.close();
    }catch (Exception e)
    {System.err.println("File input error");}
    else
    {System.out.println("Invalid parameters");}
    }

  • Calling C binary file

    I've been having this problem of trying to call a C binary file from the command line of my java program. I have followed tutorials, etc on creating the binary files and the command from the java (Runtime.getRuntime().exec(String[])), but when I try to use it, nothing happens. The thing is, I need to have the 1st arg be my program, and the 2nd and third args change the stdin/stdout in the C program. Thus, my line of code looks like:
    Process p = Runtime.getRuntime().exec(new String[] {"primer3", "<inputfile", ">outputfile.txt"});
    where inputfile is an extentionless file containing the correct input for the program, and outputfile.txt is an already created file in the same directory as the program and inputfile. If I run it through the DOS prompt, in the directory of the program and I type:
    C:\......\> primer3 <inputfile >outputfile.txt
    it works perfectly (whether or not outputfile.txt exists, in fact.) So basically, I'm wondering what I'm doing wrong here. Have I missed something?

    I've made acouple of updates and I feel like I'm almost there... just have to get stdout working. My new code looks like:
    String[] exece = new String[] {"cmd.exe", "/C", "start", "file:/c:/primer3" "<inputfile >outputfile.txt"};
    Runtime rt = Runtime.getRuntime();
    Process proc = rt.exec(exece);
    leaving out try/catch statements. Unfortunately it seems to run, but the output file has nothing in it. Do i need to do something else for the second arg?

  • How can I convert Binary File to Normal Text File?

    Hi,
    I need to read a binary file and need to conevrt as normal text file. The binary file contains some number & String (Names) with fixed length. It is the combination of Char, String, Integer, Byte & Single Bit.
    I used DataInputStream but I didnt get the expected output. Can anybody help me in reading a binary file?
    Thanks & Regards,
    Pattanaik.

    http://java.sun.com/docs/books/tutorial/essential/io/dataIO.html provides an example of using DataInputStream to do what you want.

  • Making JAR file visible to code in JDeveloper

    Hi. We're using JDeveloper 9.0.5 (planning soon to upgrade to latest version) and need to get a JAR file visible to code in a Java file. The JAR file is for the Java Advanced Imaging API, JAI_WINDOWS-I586.JAR
    What do we need to do to get this working? Thank you.

    Thanks, Frank. Finally got it working. The issue was this: The JAI API has 4 different JAR files for each platform. I'd downloaded one that contained an exe; I needed the one for the CLASSPATH installation.

  • Creating Binary Files in Java

    Does anyone know how to create a binary file in Java.
    in C i can do an fopen("filename" , "rb") i cannot find a equivalent java binary file stream.
    Thanks

    The following code is part of my FileIO applet. This method allows the user to download any file from my server and save it on his/her disk, the download is accomplished by doing a byte-read and byte-write (byte mover as I'd call it). This example illustrates how you can read and write binary files in Java:
       public void aok_DownLoad(String inputFile, String outputFile) {
          try {
             URL url=new URL(inputFile);
             InputStream in;
             in=url.openStream();
             BufferedInputStream reader=new BufferedInputStream(in,4096);
             FileOutputStream out=new FileOutputStream(outputFile);
             BufferedOutputStream writer=new BufferedOutputStream(out,4096);
             byte[] buf=new byte[4096];
             int byteRead;
             while ((byteRead=reader.read(buf,0,4096))>=0) {writer.write(buf,0,byteRead);}
             reader.close();
             writer.flush();
             writer.close();
          catch (Throwable exception) {
             exception.printStackTrace();
       }V.V.
    PS: in this posting the code is posted in a different manner so that the > sign is not converted to & gt ; by the forum's software

  • Help:how to use java.util.jar to zip or unzip a binary file.

    how to use java.util.jar to zip or unzip a binary file or a file contain native code.

    It may help you to know how I add JARs
    1. I open my Project (myProject)
    2. I Mount the JAR to the FileSystem (like mypackages.jar = which includes com.mus.de.myClass.java)
    3. I Mount the File to the FileSystem (like c:\..myfiles..\myProject)
    3.1 I add the File to my Project
    4. I select File | New -> Classes | Main
    4.1 I typed "import com.mus.de.myClass.java" to refer to this package.
    4.2 I called some of the public methods
    thats it
    Andreas

  • How to read non-java binary file?

    Hello Team,
    I have problem to read non-java binary file.
    Let me explain.... I have one binary file created in vc++ having fix structure. Structure of file is like String,int,int,int.
    Now I have to read this file in my java application. I am failed to identify length of String value of Structure in java.
    Can any body help me to solve this problem?
    Thanks in advance.
    - Pathik

    Thanks for guide me,
    I have try using 0x00. And its working.
    Now I have another problem:
    in file.ext , I have written one record having structure string,int and int.
    I have enter data as "HelloWorld", 100 and 111.
    To read first record from file file.ext, following code I am using:
    try
         FileInputStream fis = new FileInputStream("file.ext");
         DataInputStream in = new DataInputStream(fis);
         char ch;
         while((ch=(char)in.readByte()) != 0x00)
              System.out.print(ch+"");
    System.out.println();
         System.out.println("Integer 1 --> " + in.readInt());
         System.out.println("Integer 2 --> " + in.readInt());
         in.close();
         fis.close();
    catch(Exception ex)
         System.out.println(ex.toString());
    And I am getting following output:
    HelloWorld
    Integer 1 --> 0
    Integer 2 --> 0
    File file.ext is created in vc++
    I am not getting integer data. Plz guide me for this problem.
    Thanks in advance
    - Pathik

  • DE PDP-1 binary file from Java

    Can someone here help me, please!?
    Anyone know how to convert a Java class file into a binary file that will run natively on my Digital PDP-1 computer? I just spent over $120,000 for it! Thanks.
    This resurrected thread was first posted November 25, 1960 at 8:25AM
    -------------------------------------------------------------------------

    This resurrected thread was first posted November 25,
    1960 at 8:25AMIn what time zone?

  • Binary file, java

    Binary file, java, please fix these to just work when we try to download anything, Firefox 5 for example. I like to use Firefox desktop and mobile. It happens every time I download binary file, java script.

    FileInputStream

  • Read binary file in java

    To read a text file i used
    FileReader reader=new FileReader("d:/a.txt");
    please guide me on how to read a binary file in java
    Any input would be greatly appreciated!
    Thanks in advance!
    Edited by: nikkj on Aug 7, 2010 7:36 PM

    I'll give you the quick answer: you use Readers for character streams (e.g., text files) and InputStreams for binary streams (e.g., binary files).
    Still, read the tutorial. You will find out lots of useful info.

  • Binary files in java

    hi
    I am a bit new to java and am having some problems with binary files. What I need to do is search a binary file for any accurances of the data contained with in another set of binary files. I need to know if the first file contains any of the signatures in the set of files. any help would be great.
    thanks very much
    Colin

    you take your file, you read in some bytes and you loop thru those bytes to find matching bytes that you are looking for. Here's some cdoe that's probably not as elegant as it could be, but you get what you pay for.
    public static int indexOf(byte[] a, byte[] b) {
       return indexOf(a, b, 0);
    public static int indexOf(byte[] a, byte[] b, int start) {
       if(a == null || b == null || a.length == 0 || b.length == 0 || a.length < b.length) {
          return -1;
    outer:   for(int i = start; i < a.length-b.length; i++) {
          if(a[i] == b[0]) {
             for(int j = 0; j < b.length; j++) {
                if(a[i+j] != b[j]) {
                   break outer;
             return i;
    }

  • URGENT : Need java code snippet to retrieve uniquemember values OID 11g API

    Hi All,
    We have a requirement to retrieve the uniquemember attribute values using OID 11g API. We are using labeleduri approach for dynamic groups and thus all the uniquemember values are created using dynamic groups.
    When we are trying to retrieve the uniquemember values using Java code snippet, it is not returning the values. The strange thing is: The uniquemember values created using dynamic groups are not visible in ODSM OID console or JExplorer tool. However those values are visible in LDAP Browser v2.8.1 tool.
    So can somebody throw light on this? Any pointers or sample code snippet to retrieve uniquemember values would be grateful.
    Thanks
    Mahendra.

    Hi All,
    We have a requirement to retrieve the uniquemember attribute values using OID 11g API. We are using labeleduri approach for dynamic groups and thus all the uniquemember values are created using dynamic groups.
    When we are trying to retrieve the uniquemember values using Java code snippet, it is not returning the values. The strange thing is: The uniquemember values created using dynamic groups are not visible in ODSM OID console or JExplorer tool. However those values are visible in LDAP Browser v2.8.1 tool.
    So can somebody throw light on this? Any pointers or sample code snippet to retrieve uniquemember values would be grateful.
    Thanks
    Mahendra.

Maybe you are looking for

  • How to display Cell Text in Report?

    Hello, The users want to add cell text (comments) to their data for the controllers. The users are asked to enter their comments on a certain intersection of cells (e.ge. Total Year -> Plan -> Product unspecified). We want to display a report with th

  • Connect Apple TV to TV and Hi-Fi simultaneously?

    Hi all I have a compatible TV, but not a surround sound system. Is it possible to simultaneously connect an Apple TV to both the TV and my hi-fi, to play sound out through the hi-fi?

  • Mac Crashes - Log indicates problem with Dock

    My MAC hangs once in a few hours (fairly random) and the Crash Log seems to indicate it is a problem with the Dock Application. There is no correlation between other applications that I am using and the crash. Many times it happens soon after boot up

  • Selecting Objects in Illustrator - selecting objects only completely contained within your selection box

    Hi Macbook Pro, Illustrator CC 2014.1.0 When selecting objects in Illustrator using a selection box created by dragging a selection tool, everything that the box touches gets selected.  On programs like AutoCad, there are options to select only what

  • Switching from write through to write behind automatically

    Hi, We are considering a Coherence solution to protect a customer facing application from outages due to database failures. This is for a financial company and the monetary value of each transaction is large and we want to provide 100% guarantee agai