Results 1 to 3 of 3
Thread: Reverse Packer
- 04-08-2012, 06:37 AM #1
Member
- Join Date
- Dec 2011
- Posts
- 16
- Rep Power
- 0
Reverse Packer
Hello could someone teach/help me how to reverse this java file. It packs a txt file into a bunch of other files and I would like to be able to reverse it. Willing to learn!
-.gif)
Also have this if it helps.. Sorry i'm new to javaJava Code:package com.rs.utils; import java.io.BufferedReader; import java.io.DataOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.FileReader; import java.io.RandomAccessFile; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; import java.nio.channels.FileChannel.MapMode; import com.rs.game.World; import com.rs.game.WorldTile; public final class NPCSpawns { public static final void init() { if (!new File("data/npcs/packedSpawns").exists()) packNPCSpawns(); } private static final void packNPCSpawns() { Logger.log("NPCSpawns", "Packing npc spawns..."); if (!new File("data/npcs/packedSpawns").mkdir()) throw new RuntimeException( "Couldn't create packedSpawns directory."); try { BufferedReader in = new BufferedReader(new FileReader( "data/npcs/unpackedSpawnsList.txt")); while (true) { String line = in.readLine(); if (line == null) break; if (line.startsWith("//")) continue; String[] splitedLine = line.split(" - ", 2); if (splitedLine.length != 2) throw new RuntimeException("Invalid NPC Spawn line: " + line); int npcId = Integer.parseInt(splitedLine[0]); String[] splitedLine2 = splitedLine[1].split(" ", 5); if (splitedLine2.length != 3 && splitedLine2.length != 5) throw new RuntimeException("Invalid NPC Spawn line: " + line); WorldTile tile = new WorldTile( Integer.parseInt(splitedLine2[0]), Integer.parseInt(splitedLine2[1]), Integer.parseInt(splitedLine2[2])); int mapAreaNameHash = -1; boolean canBeAttackFromOutOfArea = true; if (splitedLine2.length == 5) { mapAreaNameHash = Utils.getNameHash(splitedLine2[3]); canBeAttackFromOutOfArea = Boolean .parseBoolean(splitedLine2[4]); } addNPCSpawn(npcId, tile.getRegionId(), tile, mapAreaNameHash, canBeAttackFromOutOfArea); } in.close(); } catch (Throwable e) { Logger.handle(e); } } public static final void loadNPCSpawns(int regionId) { File file = new File("data/npcs/packedSpawns/" + regionId + ".ns"); if (!file.exists()) return; try { RandomAccessFile in = new RandomAccessFile(file, "r"); FileChannel channel = in.getChannel(); ByteBuffer buffer = channel.map(MapMode.READ_ONLY, 0, channel.size()); while (buffer.hasRemaining()) { int npcId = buffer.getShort() & 0xffff; int plane = buffer.get() & 0xff; int x = buffer.getShort() & 0xffff; int y = buffer.getShort() & 0xffff; boolean hashExtraInformation = buffer.get() == 1; int mapAreaNameHash = -1; boolean canBeAttackFromOutOfArea = true; if (hashExtraInformation) { mapAreaNameHash = buffer.getInt(); canBeAttackFromOutOfArea = buffer.get() == 1; } World.spawnNPC(npcId, new WorldTile(x, y, plane), mapAreaNameHash, canBeAttackFromOutOfArea); } channel.close(); in.close(); } catch (Throwable e) { Logger.handle(e); } } private static final void addNPCSpawn(int npcId, int regionId, WorldTile tile, int mapAreaNameHash, boolean canBeAttackFromOutOfArea) { try { DataOutputStream out = new DataOutputStream(new FileOutputStream( "data/npcs/packedSpawns/" + regionId + ".ns", true)); out.writeShort(npcId); out.writeByte(tile.getPlane()); out.writeShort(tile.getX()); out.writeShort(tile.getY()); out.writeBoolean(mapAreaNameHash != -1); if (mapAreaNameHash != -1) { out.writeInt(mapAreaNameHash); out.writeBoolean(canBeAttackFromOutOfArea); } out.flush(); out.close(); } catch (Throwable e) { Logger.handle(e); } } private NPCSpawns() { } }
Java Code:package com.rs.tools; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; import com.rs.cache.Cache; import com.rs.io.InputStream; import com.rs.utils.Logger; import com.rs.utils.MapContainersXteas; public class NPCSpawnsDumper { private static int writtenCount; public static final void main(String[] args) throws IOException { BufferedWriter out = new BufferedWriter(new FileWriter( "data/npcs/unpackedSpawnsList.txt", true)); Logger.log("Launcher", "Initing Cache..."); Cache.init(); Logger.log("Launcher", "Initing Data File..."); MapContainersXteas.init(); for (int regionId = 0; regionId < 20000; regionId++) { //if (new File("data/npcs/packedSpawns/" + regionId + ".ns").exists()) //continue; dumpRegionNPCs(regionId, out); } out.close(); System.out.println("found " + writtenCount + " npc spawns on cache."); } public static final void dumpRegionNPCs(int regionId, BufferedWriter writer) throws IOException { writer.flush(); int regionX = (regionId >> 8) * 64; int regionY = (regionId & 0xff) * 64; int npcSpawnsContainerId = Cache.STORE.getIndexes()[5].getArchiveId("n" + ((regionX >> 3) / 8) + "_" + ((regionY >> 3) / 8)); if (npcSpawnsContainerId == -1) return; byte[] npcSpawnsContainerData = Cache.STORE.getIndexes()[5].getFile( npcSpawnsContainerId, 0, null); if (npcSpawnsContainerData == null) return; System.out.println(regionId); InputStream stream = new InputStream(npcSpawnsContainerData); while (stream.getRemaining() > 0) { int hash = stream.readUnsignedShort(); int npcId = stream.readUnsignedShort(); int plane = hash >> 758085070; int localX = (0x1f92 & hash) >> -585992921; int x = regionX + localX; int localY = 0x3f & hash; int y = regionY + localY; writer.newLine(); writer.write(npcId + ":" + x + ":" + y + ":" + plane); writer.flush(); writtenCount++; } } }Last edited by Sean2012; 04-08-2012 at 06:40 AM.
- 04-08-2012, 10:46 AM #2
Senior Member
- Join Date
- Oct 2011
- Posts
- 106
- Rep Power
- 0
Re: Reverse Packer
Sorry, no one here is going to reverse engineer this app for you. If you have a specific question about part of the code, I would segregate that code snippet and ask a specific question in regards to it.
- 04-08-2012, 05:03 PM #3
Member
- Join Date
- Dec 2011
- Posts
- 16
- Rep Power
- 0
Similar Threads
-
Reverse
By system5634 in forum New To JavaReplies: 2Last Post: 03-26-2012, 09:55 AM -
how to reverse string without using string reverse or array ?
By funkygarzon in forum New To JavaReplies: 10Last Post: 03-15-2012, 10:46 AM -
reverse engineering
By kulangotski in forum Advanced JavaReplies: 9Last Post: 12-11-2011, 01:41 PM -
Reverse the integers
By aramiky818 in forum New To JavaReplies: 3Last Post: 04-23-2011, 07:17 PM -
How to reverse something really stupid I did... HELP PLEASE
By efebatistaarda in forum NetBeansReplies: 0Last Post: 02-15-2011, 11:16 PM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks