Рейтинг темы:
  • 0 Голос(ов) - 0 в среднем
  • 1
  • 2
  • 3
  • 4
  • 5
Opcode Obfuscator
#1
хз может это давно в шаре, но я дописывал сам эту хрень( брал у опенов и дописывал)
с этой хренью сложнее пользоваться хлапой( по крайней мере на обт люди писали так)
PHP код:
<?php 
/**
*@author Darvin
* date:08.11.2011
* time:0:35:36
*/
public class OpcodeObfuscator
{
private
boolean m_enabled;
private
int m_rand_seed;
private
int m_size1;
private
int m_size2;
private
int m_size3;
private
int[] m_decodeTable1;
private
int[] m_decodeTable2;
private
int[] m_decodeTable3;

public
OpcodeObfuscator()
{
disable();
}

public
void disable()
{
m_enabled = false;
m_rand_seed = 0;
m_size1 = m_size2 = m_size3 = 0;
m_decodeTable1 = m_decodeTable2 = m_decodeTable3 = null;
}

public
void init_tables(int paramInt)
{
int i = 0;
int j = 0;
int k = 0;
int l = 0;
m_size1 = 208;
m_size2 = 0x68; //0x63
m_size3 = 6;
m_decodeTable1 = new int[m_size1 + 1];
m_decodeTable2 = new int[m_size2 + 1];
m_decodeTable3 = new int[m_size3 + 1];
for (
i = 0; i <= m_size1; ++i)
{
m_decodeTable1[i] = i;
}
for (
i = 0; i <= m_size2; ++i)
{
m_decodeTable2[i] = i;
}
for (
i = 0; i <= m_size3; ++i)
{
m_decodeTable3[i] = i;
}
pseudo_rand_seed(paramInt);
for (
i = 1; i <= m_size1; ++i)
{
k = pseudo_rand() % (i + 1);
j = m_decodeTable1[k];
m_decodeTable1[k] = m_decodeTable1[i];
m_decodeTable1[i] = j;
}
for (
i = 1; i <= m_size2; ++i)
{
k = pseudo_rand() % (i + 1);
j = m_decodeTable2[k];
m_decodeTable2[k] = m_decodeTable2[i];
m_decodeTable2[i] = j;
}
for (
i = 1; i <= m_size3; ++i)
{
k = pseudo_rand() % (i + 1);
j = m_decodeTable3[k];
m_decodeTable3[k] = m_decodeTable3[i];
m_decodeTable3[i] = j;
}
for (
l = 0; m_decodeTable1[l] != 18; ++l)
{
;
}
j = m_decodeTable1[18];
m_decodeTable1[18] = 18;
m_decodeTable1[l] = j;
for (
l = 0; m_decodeTable1[l] != 177; ++l)
{
;
}
j = m_decodeTable1[177];
m_decodeTable1[177] = 177;
m_decodeTable1[l] = j;
m_enabled = true;
}

public
int decodeSingleOpcode(int paramInt)
{
if (!(
m_enabled))
{
return
paramInt;
}
if (
paramInt > m_size1)
{
return
paramInt;
}
paramInt = m_decodeTable1[paramInt];
return
paramInt;
}

public
int decodeDoubleOpcode(int paramInt)
{
if (!(
m_enabled))
{
return
paramInt;
}
if (
paramInt > m_size2)
{
return
paramInt;
}
paramInt = m_decodeTable2[paramInt];
return
paramInt;
}

public
int decodeTripleOpcode(int paramInt)
{
return
paramInt;
}

private
void pseudo_rand_seed(int paramInt)
{
m_rand_seed = paramInt;
}

private
int pseudo_rand()
{
int i = m_rand_seed * 214013 + 2531011 & 0xFFFFFFFF;
m_rand_seed = i;
int j = m_rand_seed >> 16 & 0x7FFF;
return
j;
}
}
кому помог тыкай спасибо и ставь +

в придачу выложу свой L2GameClient а по пакетам распихивайте обфускатор сами
PHP код:
<?php 
package l2open
.gameserver.network;

import drin.nativeLib.Deflater;
import l2open.Config;
import l2open.database.DatabaseUtils;
import l2open.database.FiltredPreparedStatement;
import l2open.database.L2DatabaseFactory;
import l2open.database.ThreadConnection;
import l2open.extensions.network.MMOClient;
import l2open.extensions.network.MMOConnection;
import l2open.gameserver.GameTimeController;
import l2open.gameserver.cache.Msg;
import l2open.gameserver.controllers.SecondaryPasswordController;
import l2open.gameserver.instancemanager.PlayerManager;
import l2open.gameserver.loginservercon.LSConnection;
import l2open.gameserver.loginservercon.SessionKey;
import l2open.gameserver.loginservercon.gspackets.PlayerLogout;
import l2open.gameserver.loginservercon.gspackets.PointConnection;
import l2open.gameserver.model.CharSelectInfoPackage;
import l2open.gameserver.model.L2ObjectsStorage;
import l2open.gameserver.model.L2Player;
import l2open.gameserver.network.PacketFloodProtector.ActionType;
import l2open.gameserver.network.PacketFloodProtector.PacketData;
import l2open.gameserver.serverpackets.L2GameServerPacket;
import l2open.gameserver.templates.StatsSet;
import l2open.util.GArray;
import l2open.util.HWID.HardwareID;
import java.nio.ByteBuffer;
import java.util.Collection;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
* Represents a client connected on Game Server
*/
public final class L2GameClient extends MMOClient<MMOConnection<L2GameClient>>
{
protected static
Logger _log = Logger.getLogger(L2GameClient.class.getName());

public
GameCrypt _crypt = null;
private
float _bonus = 1;
private
long _bonus_expire = 0;
public
GameClientState _state;
private
int _upTryes = 0, _upTryesTotal = 0;
private
long _upTryesRefresh = 0;
private
int point = 0;
private
OpcodeObfuscator obf;
private
int keyObf = 0;

// Flood Protect
private Map<Integer, Integer> _packets;

public
void setObfKey(int obfKey)
{
keyObf = obfKey;
}

public
int getObfKey()
{
return
keyObf;
}

public
void enableOpcodeObfuscation(int obfKey)
{
if (
obf == null)
obf = new OpcodeObfuscator();
else
obf.disable();
obf.init_tables(obfKey);
}

public
void disableOpcodeObfuscation()
{
if (
obf == null)
return;
obf.disable();
}

public
OpcodeObfuscator getObfuscator()
{
if (
obf == null)
obf = new OpcodeObfuscator();
return
obf;
}
public
void setPoint(int point)
{
this.point = point;
LSConnection.getInstance().sendPacket(new PointConnection(getLoginName(), getPoint()));
}

public
int getPoint()
{
return
point;
}

public static enum
GameClientState
{
CONNECTED,
AUTHED,
IN_GAME
}

private
String _loginName;
private
L2Player _activeChar;
private
SessionKey _sessionId = null;
private
MMOConnection<L2GameClient> _connection = null;

//private byte[] _filter;

private int revision = 0;
private
boolean _gameGuardOk = false;

public
boolean protect_used = false;
public
byte client_lang = -1;
public
HardwareID HWID = null;

private
GArray<Integer> _charSlotMapping = new GArray<Integer>();
private
PacketLogger pktLogger = null;
private
boolean pktLoggerMatch = false;
public
StatsSet account_fields = null;
public
Deflater deflater = null;

public
L2GameClient(MMOConnection<L2GameClient> con, boolean offline)
{
super(con);
if(!
offline)
{
_state = GameClientState.CONNECTED;
_connection = con;
_sessionId = new SessionKey(-1, -1, -1, -1);
_crypt = new GameCrypt();
if(
Config.PROTECT_ENABLE)
protect_used = !Config.PROTECT_UNPROTECTED_IPS.isIpInNets(getIpAddr());

if(
Config.LOG_CLIENT_PACKETS || Config.LOG_SERVER_PACKETS)
{
pktLogger = new PacketLogger(this, Config.PACKETLOGGER_FLUSH_SIZE);
if(
Config.PACKETLOGGER_IPS != null)
if(
Config.PACKETLOGGER_IPS.isIpInNets(getIpAddr()))
pktLoggerMatch = true;
}
}
else
_state = GameClientState.IN_GAME;
}

public
L2GameClient(MMOConnection<L2GameClient> con)
{
this(con, false);
}

public
void OnOfflineTrade()
{
deflater = null;
_charSlotMapping = null;
}

public
void disconnectOffline()
{
onDisconnection();
}

@
Override
protected void onDisconnection()
{
if(
pktLogger != null)
{
if(!
pktLogger.assigned() && pktLoggerMatch)
pktLogger.assign();
pktLogger.close();
pktLogger = null;
}

if(
getLoginName() == null || getLoginName().equals("") || _state != GameClientState.IN_GAME && _state != GameClientState.AUTHED)
return;
try
{
if(
_activeChar != null && _activeChar.isInOfflineMode())
//LSConnection.getInstance().sendPacket(new PlayerLogout(getLoginName()));
return;

LSConnection.getInstance().removeAccount(this);
L2Player player = _activeChar;
_activeChar = null;

if(
player != null && !player.isLogoutStarted()) // this should only happen on connection loss
{
player.scheduleDelete(Config.PLAYER_DISCONNECT_INGAME_TIME);
if(
player.getNetConnection() != null)
{
if(!
player.isInOfflineMode())
player.getNetConnection().closeNow(false);
player.setNetConnection(null);
}
player.setConnected(false);
if(
Config.PLAYER_DISCONNECT_INGAME_TIME > 0)
player.broadcastUserInfo(false);
_activeChar = null;
}

setConnection(null);
}
catch(
Exception e1)
{
_log.log(Level.WARNING, "error while disconnecting client", e1);
}
finally
{
LSConnection.getInstance().sendPacket(new PlayerLogout(getLoginName()));
}
super.onDisconnection();
}

public
void markRestoredChar(int charslot) throws Exception
{
int objid = getObjectIdForSlot(charslot);
if(
objid < 0)
return;

if(
_activeChar != null && _activeChar.getObjectId() == objid)
_activeChar.setDeleteTimer(0);

ThreadConnection con = null;
FiltredPreparedStatement statement = null;
try
{
con = L2DatabaseFactory.getInstance().getConnection();
statement = con.prepareStatement("UPDATE characters SET deletetime=0 WHERE obj_id=?");
statement.setInt(1, objid);
statement.execute();
}
catch(
Exception e)
{
_log.log(Level.WARNING, "data error on restore char:", e);
e.printStackTrace();
}
finally
{
DatabaseUtils.closeDatabaseCS(con, statement);
}
}

public
void markToDeleteChar(int charslot) throws Exception
{
int objid = getObjectIdForSlot(charslot);
if(
objid < 0)
return;

if(
_activeChar != null && _activeChar.getObjectId() == objid)
_activeChar.setDeleteTimer((int) (System.currentTimeMillis() / 1000));

ThreadConnection con = null;
FiltredPreparedStatement statement = null;
try
{
con = L2DatabaseFactory.getInstance().getConnection();
statement = con.prepareStatement("UPDATE characters SET deletetime=? WHERE obj_id=?");
statement.setLong(1, (int) (System.currentTimeMillis() / 1000));
statement.setInt(2, objid);
statement.execute();
}
catch(
Exception e)
{
_log.log(Level.WARNING, "data error on update deletime char:", e);
e.printStackTrace();
}
finally
{
DatabaseUtils.closeDatabaseCS(con, statement);
}
}

public
void deleteChar(int charslot) throws Exception
{
//have to make sure active character must be nulled
if(_activeChar != null)
{
_activeChar.logout(false, false, true, true);
_activeChar = null;
}

int objid = getObjectIdForSlot(charslot);
if(
objid == -1)
return;

PlayerManager.deleteCharByObjId(objid);
}

public
boolean hasHWID()
{
return
HWID != null;
}

public
L2Player loadCharFromDisk(int charslot)
{
Integer objectId = getObjectIdForSlot(charslot);
if(
objectId == -1)
return
null;

L2Player character = null;
L2Player old_player = L2ObjectsStorage.getPlayer(objectId);

if(
old_player != null)
if(
old_player.isInOfflineMode() || old_player.isLogoutStarted())
// оффтрейдового чара проще выбить чем восстанавливать
old_player.logout(false, false, true, true);
else
{
old_player.sendPacket(Msg.ANOTHER_PERSON_HAS_LOGGED_IN_WITH_THE_SAME_ACCOUNT);
LSConnection.getInstance().sendPacket(new PlayerLogout(getLoginName()));

if(
old_player.getNetConnection() != null)
{
old_player.getNetConnection().setActiveChar(null);
old_player.getNetConnection().closeNow(false);
}
old_player.setLogoutStarted(false);
old_player.setNetConnection(this);
character = old_player;
}

if(
character == null)
character = L2Player.restore(objectId);

if(
character != null)
{
// preinit some values for each login
character.setRunning(); // running is default
character.standUp(); // standing is default

character.updateStats();
character.setOnlineStatus(true);
setActiveChar(character);
character.restoreBonus();
character.bookmarks.restore();
if(
Config.USE_CLIENT_LANG)
switch(
client_lang)
{
case
0:
character.setVar("lang@", "en");
break;
case
1:
character.setVar("lang@", "ru");
break;
}
if(
protect_used && Config.PROTECT_GS_STORE_HWID && hasHWID())
character.storeHWID(HWID.Full);

if(
pktLogger != null)
if(!
pktLogger.assigned())
{
if(!
pktLoggerMatch)
if(
Config.PACKETLOGGER_CHARACTERS != null)
{
String char_name = character.getName();
for(
int i = 0; i < Config.PACKETLOGGER_CHARACTERS.size(); i++)
{
String s_mask = Config.PACKETLOGGER_CHARACTERS.get(i);
if(
char_name.matches(s_mask))
{
pktLoggerMatch = true;
break;
}
}
}
if(
pktLoggerMatch)
pktLogger.assign();
else
pktLogger = null;
}
}
else
_log.warning("could not restore obj_id: " + objectId + " in slot:" + charslot);

return
character;
}

public
int getObjectIdForSlot(int charslot)
{
if(
charslot < 0 || charslot >= _charSlotMapping.size())
{
_log.warning(getLoginName() + " tried to modify Character in slot " + charslot + " but no characters exits at that slot.");
return -
1;
}
return
_charSlotMapping.get(charslot);
}

@
Override
public MMOConnection<L2GameClient> getConnection()
{
return
_connection;
}

public
L2Player getActiveChar()
{
return
_activeChar;
}

/**
* @return Returns the sessionId.
*/
public SessionKey getSessionId()
{
return
_sessionId;
}

public
String getLoginName()
{
return
_loginName;
}

private
void logHWID()
{
ThreadConnection con = null;
FiltredPreparedStatement statement = null;
try
{
con = L2DatabaseFactory.getInstance().getConnection();
statement = con.prepareStatement(Config.PROTECT_GS_LOG_HWID_QUERY);
statement.setString(1, _loginName);
statement.setString(2, getIpAddr());
statement.setString(3, HWID.Full);
statement.execute();
}
catch(final
Exception e)
{
_log.warning("could not log HWID:" + e);
}
finally
{
DatabaseUtils.closeDatabaseCS(con, statement);
}
}

public
void setLoginName(String loginName)
{
_loginName = loginName;
if(
protect_used && Config.PROTECT_GS_LOG_HWID && getIpAddr() != "Disconnected")
logHWID();

if(
pktLogger != null && !pktLoggerMatch && Config.PACKETLOGGER_ACCOUNTS != null)
for(
int i = 0; i < Config.PACKETLOGGER_ACCOUNTS.size(); i++)
{
String s_mask = Config.PACKETLOGGER_ACCOUNTS.get(i);
if(
loginName.matches(s_mask))
{
pktLoggerMatch = true;
break;
}
}
}

public
void setActiveChar(L2Player cha)
{
_activeChar = cha;
if(
cha != null)
// we store the connection in the player object so that external
// events can directly send events to the players client
// might be changed later to use a central event management and distribution system
_activeChar.setNetConnection(this);
}

public
void setSessionId(SessionKey sessionKey)
{
_sessionId = sessionKey;
}

public
void setCharSelection(CharSelectInfoPackage[] chars)
{
_charSlotMapping.clear();

for(
CharSelectInfoPackage element : chars)
{
int objectId = element.getObjectId();
_charSlotMapping.add(objectId);
}
}

public
void setCharSelection(int c)
{
_charSlotMapping.clear();
_charSlotMapping.add(c);
}

/**
* @return Returns the revision.
*/
public int getRevision()
{
return
revision;
}

/**
* @param revision The revision to set.
*/
public void setRevision(int revision)
{
this.revision = revision;
}

public
void setGameGuardOk(boolean gameGuardOk)
{
_gameGuardOk = gameGuardOk;
}

public
boolean isGameGuardOk()
{
return
_gameGuardOk;
}

@
Override
public boolean encrypt(final ByteBuffer buf, final int size)
{
if(
pktLogger != null && Config.LOG_SERVER_PACKETS)
pktLogger.log_packet((byte) 1, buf, size);
_crypt.encrypt(buf.array(), buf.position(), size);
buf.position(buf.position() + size);
return
true;
}

@
Override
public boolean decrypt(ByteBuffer buf, int size)
{
_crypt.decrypt(buf.array(), buf.position(), size);
if (
pktLogger != null && Config.LOG_CLIENT_PACKETS)
pktLogger.log_packet((byte) 0, buf, size);
return
true;
}

public
void sendPacket(L2GameServerPacket... gsp)
{
if(
getConnection() == null)
return;
getConnection().sendPacket(gsp);
}

@
SuppressWarnings("unchecked")
public
void sendPackets(Collection<L2GameServerPacket> gsp)
{
if(
getConnection() == null)
return;
getConnection().sendPackets((Collection) gsp);
}

public
void close(L2GameServerPacket gsp)
{
getConnection().close(gsp);
}

public
String getIpAddr()
{
try
{
return
_connection.getSocket().getInetAddress().getHostAddress();
}
catch(
NullPointerException e)
{
return
"Disconnected";
}
}

public
byte[] enableCrypt()
{
//initCompression();
byte[] key = BlowFishKeygen.getRandomKey();
_crypt.setKey(key, protect_used);
return
key;
}

//public void initCompression()
//{
// if(protect_used && Config.PROTECT_COMPRESSION > 0 && Config.PROTECT_COMPRESSION < 10)
// deflater = new Deflater(Config.PROTECT_COMPRESSION, true);
//}

public float getBonus()
{
return
_bonus;
}

public
void setBonus(float bonus)
{
_bonus = bonus;
}

/**
* @return время окончания бонуса в unixtime
*/
public long getBonusExpire()
{
return
_bonus_expire;
}

public
void setBonusExpire(long time)
{
if(
time < 0)
return;
if(
time < System.currentTimeMillis() / 1000)
{
_bonus = 1;
return;
}
_bonus_expire = time;
}

public
GameClientState getState()
{
return
_state;
}

public
void setState(GameClientState state)
{
_state = state;
}

/**
* @return произведено ли отключение игрока
*/
public boolean onClientPacketFail()
{
if(
isPacketsFailed())
return
true;

if(
_upTryesRefresh == 0)
_upTryesRefresh = System.currentTimeMillis() + 5000;
else if(
_upTryesRefresh < System.currentTimeMillis())
{
_upTryesRefresh = System.currentTimeMillis() + 5000;
_upTryes = 0;
}

_upTryes++;
_upTryesTotal++;

if(
_upTryes > 4 || _upTryesTotal > 10)
{
_log.warning("Too many client packet fails, connection closed. IP: " + getIpAddr() + ", account:" + getLoginName());
L2Player activeChar = getActiveChar();
if(
activeChar != null)
activeChar.logout(false, false, true, true);
else
closeNow(true);
_upTryesTotal = Integer.MAX_VALUE;
return
true;
}

return
false;
}

public
boolean isPacketsFailed()
{
return
_upTryesTotal == Integer.MAX_VALUE;
}

public
Deflater getDeflater()
{
return
deflater;
}

public
ActionType checkPacket(int packetId)
{
PacketData pd = PacketFloodProtector.getInstance().getDataByPacketId(packetId);
if(
pd != null)
{
if(
_packets.containsKey(packetId))
{
if(
pd.getDelay() > (GameTimeController.getGameTicks() - _packets.get(packetId)) * 100)
{
_packets.put(packetId, GameTimeController.getGameTicks());
return
pd.getAction();
}
else
{
_packets.put(packetId, GameTimeController.getGameTicks());
return
ActionType.none;
}
}
else
{
_packets.put(packetId, GameTimeController.getGameTicks());
return
ActionType.none;
}
}
return
ActionType.none;
}

@
Override
public String toString()
{
return
"L2GameClient: " + (_activeChar == null ? _loginName : _activeChar) + "@" + getIpAddr();
}
private
SecondaryPasswordController _secondaryAuth;
public
SecondaryPasswordController getSecondaryAuth()
{
return
_secondaryAuth;
}
}
Ответ
#2
обфускатор опкодов есть под опенсорс лицензией http://fisheye.l2jfree.com/browse/l2jfre...va?hb=true
Ответ
#3
Big Grin ну если пошло на то , - весь сорс это конвертация С++ в яву

http://code.google.com/p/l2packets/sourc...scator.cpp
Ответ
#4
VISTALL Написал:Big Grin ну если пошло на то , - весь сорс это конвертация С++ в яву

http://code.google.com/p/l2packets/sourc...scator.cpp

как бы в моем источнике это указано в комментарии Big Grin
Ответ
#5
а можно пример хоть одного пакета, изучение требует примеры Smile
Ответ
#6
тут более простой обфускатор,
хз мне и мой нравиться
Ответ
#7
Darvin Написал:тут более простой обфускатор,
хз мне и мой нравиться

оно не меняет пакет - а ток его опкод , и ток по шаблону который сгенерированый, - обходится просто
Ответ
#8
ни кто не сказал что это защита от хлапы и тд, с ней просто немного сложнее изменить пакет
Ответ
#9
создана новая тема http://forum.zone-game.info/showthread.p...post218047
Ответ
#10
flopix, посмотрите на дату последнего сообщения.
Fortuna - non penis, in manus non recipe.
Ответ


Возможно похожие темы ...
Тема Автор Ответы Просмотры Последний пост
  Интересует алгоритм Opcode Obfuscator-а flopix 1 2,322 06-13-2013, 11:56 AM
Последний пост: Be3geBJIa3
  Opcode obfuscation horato 4 2,820 12-27-2012, 01:45 PM
Последний пост: horato

Перейти к форуму:


Пользователи, просматривающие эту тему: 1 Гость(ей)