stackoverflow!
I managed to inject my dll into the game minecraft(made in java) and i did attach to the main thread so i can get classes and field.
Total code:
#include <Windows.h>
#include <jni.h>
#include <iostream>
#include <string>
#include "MCClass.h"
/*
BOOL WINAPI DllMain(
_In_ HINSTANCE hinstDLL,
_In_ DWORD fdwReason,
_In_ LPVOID lpvReserved
);
*/
typedef jint (*hJNI_GetCreatedJavaVMs )( JavaVM** vmBuf , jsize bufLen , jsize* nVMs );
hJNI_GetCreatedJavaVMs oJNI_GetCreatedJavaVMs;
HMODULE jvmHandle;
FARPROC func_JNI_GetCreatedJavaVMs;
JavaVM *jvm;
JNIEnv *jenv;
jclass Minecraft;
jclass FMLH;
jclass FMLHI;
jclass launchWrapper;
MCClass* mc = new MCClass ( );
using namespace std;
void GetAllMinecraft ( )
{
jfieldID f = jenv->GetFieldID ( Minecraft , "serverName" , "Ljava/lang/String;" );
if ( f != NULL )
{
jstring str = (jstring)jenv->GetObjectField ( Minecraft , f );
mc->serverName = (char*)jenv->GetStringUTFChars( str , 0 );
cout << mc->serverName << endl;
}
else
{
MessageBox ( NULL , "serverName is null", "ERROR" , MB_OK );
}
}
/*
void start ( )
{
MessageBox ( NULL , "Initialization has completed." , "Works" , MB_OK );
FMLH = jenv->FindClass ( "net/minecraftforge/fml/relauncher/FMLLaunchHandler" );
if ( FMLH != nullptr )
{
MessageBox ( NULL , "FMLLaunchHandler found successfully" , "OK" , MB_OK );
jfieldID f = jenv->GetStaticFieldID ( (jclass) FMLH , "INSTANCE" , "Lnet/minecraftforge/fml/relauncher/FMLLaunchHandler;" );
MessageBox ( NULL , "FMLH passed" , "OK" , MB_OK );
if ( f == nullptr )
{
MessageBox ( NULL , "FMLLaunchHandler fieldID couldn't be found successfully" , "OK" , MB_OK );
}
else
{
MessageBox ( NULL , "FMLLaunchHandler fieldID found successfully" , "OK" , MB_OK );
FMLHI = jenv->GetStaticObjectField ( (jclass) FMLH , f );
MessageBox ( NULL , "FMLHI passed" , "OK" , MB_OK );
if ( FMLHI == nullptr )
{
MessageBox ( NULL , "FMLLaunchHandler instance couldn't be found successfully" , "OK" , MB_OK );
}
else
{
MessageBox ( NULL , "FMLHI is not nullptr" , "OK" , MB_OK );
jfieldID f1 = jenv->GetFieldID ( ( jclass ) FMLHI , "classLoader" , "Lnet/minecraft/launchwrapper/LaunchClassLoader;" ); //HERE
MessageBox ( NULL , "f1 passed" , "OK" , MB_OK );
if ( f1 == nullptr )
{
MessageBox ( NULL , "classLoader fieldID couldn't be found successfully" , "OK" , MB_OK );
}
else
{
MessageBox ( NULL , "classLoader fieldID found successfully" , "OK" , MB_OK );
launchWrapper = jenv->GetObjectField ( ( jclass ) FMLHI , f1 );
MessageBox ( NULL , "launchWrapper passed" , "OK" , MB_OK );
if ( launchWrapper == nullptr )
{
MessageBox ( NULL , "classLoader class couldn't be found successfully" , "OK" , MB_OK );
}
else
{
MessageBox ( NULL , "classLoader class found successfully" , "OK" , MB_OK );
jmethodID mmid = jenv->GetMethodID ( ( jclass ) launchWrapper , "findClass" , "(Ljava/lang/String;)Ljava/lang/Class;" );
MessageBox ( NULL , "findClass passed" , "OK" , MB_OK );
if ( mmid != NULL )
{
Minecraft = ( jclass ) jenv->CallNonvirtualObjectMethod ( launchWrapper , ( jclass ) launchWrapper , mmid , "net.minecraft.client.Minecraft" );
MessageBox ( NULL , "Minecraft class found successfully" , "OK" , MB_OK );
// GetAllMinecraft ( );
}
else
{
MessageBox ( NULL , "findClass method ID couldn't be found successfully" , "OK" , MB_OK );
}
}
}
}
}
}
else
{
MessageBox ( NULL , "FMLLaunchHandler couldn't be found successfully" , "OK" , MB_OK );
}
}
*/
const char* GetObjName ( jobject cls )
{
jclass clsClazz = jenv->GetObjectClass ( cls );
jmethodID methodId = jenv->GetMethodID ( clsClazz , "getName" , "()Ljava/lang/String;" );
jstring className = ( jstring ) jenv->CallObjectMethod ( cls , methodId );
return jenv->GetStringUTFChars ( className , NULL );
jenv->DeleteLocalRef ( clsClazz );
}
void start ( )
{
jclass preMC = jenv->FindClass ( "net/minecraftforge/fml/relauncher/FMLLaunchHandler" );
if ( preMC != NULL )
{
/*Section intercept custom findClassStart*/
jfieldID iID = jenv->GetStaticFieldID ( preMC , "INSTANCE" , "Lnet/minecraftforge/fml/relauncher/FMLLaunchHandler;" );
cout << "IID: " << iID << endl;
jobject instance = jenv->GetStaticObjectField ( preMC , iID );
cout << "INSTANCE: " << instance << endl;
jfieldID lID = jenv->GetFieldID ( preMC , "classLoader" , "Lnet/minecraft/launchwrapper/LaunchClassLoader;" );
cout << "LID: " << lID << endl;
jobject classLoader = jenv->GetObjectField ( instance , lID );
cout << "classLoader: " << classLoader << endl;
jmethodID fid = jenv->GetMethodID ( jenv->GetObjectClass(classLoader) , "findClass" , "(Ljava/lang/String;)Ljava/lang/Class;" );
cout << "FID: " << fid << endl;
jobject a = jenv->CallNonvirtualObjectMethod ( classLoader , jenv->GetObjectClass(classLoader), fid , "net/minecraft/client/Minecraft" );
preMC = ( jclass ) a;
cout << "preMC: " << preMC << endl;
/*Section intercept custom findClassEND*/
/*Section getDisplayWidthStart*/
jfieldID mid = jenv->GetStaticFieldID ( jenv->GetObjectClass(preMC) , "theMinecraft" , "Lnet/minecraft/client/Minecraft;" );
cout << "MID: " << mid << endl;
jobject MC = jenv->GetStaticObjectField ( jenv->GetObjectClass(preMC) , mid );
cout << "MC: " << MC << endl;
jfieldID mid2 = jenv->GetFieldID ( jenv->GetObjectClass(MC) , "displayWidth" , "I" );
cout << "MID2: " << mid2 << endl;
int displayWidth = jenv->GetIntField ( MC , mid2 );
cout << "DisplayWidth: " << displayWidth << endl;
/*Section getDisplayWidthEND*/
}
}
void init ( )
{
jvmHandle = GetModuleHandleA ( "jvm.dll" );
func_JNI_GetCreatedJavaVMs = GetProcAddress ( jvmHandle , "JNI_GetCreatedJavaVMs" );
oJNI_GetCreatedJavaVMs = ( hJNI_GetCreatedJavaVMs ) func_JNI_GetCreatedJavaVMs;
jint returnOF = oJNI_GetCreatedJavaVMs ( &jvm , 1 , NULL );
jint returnOf1 = jvm->AttachCurrentThread ( ( void ** ) &jenv , NULL );
if ( jenv != nullptr )
{
start ( );
}
if ( jenv->ExceptionCheck ( ) )
{
jenv->ExceptionDescribe ( );
}
jvm->DetachCurrentThread ( );
}
BOOL WINAPI DllMain ( HINSTANCE hinstDLL , DWORD fdwReason , LPVOID lpvReserved )
{
switch ( fdwReason )
{
case DLL_PROCESS_ATTACH:
init ( );
//case DLL_PROCESS_DETACH:
//case DLL_THREAD_ATTACH:
//case DLL_THREAD_DETACH:
}
}
NOTE: this game uses a custom class launcher, + i use the forge api on it.
I looked at the cout debugs and looks like the cout's stop at :
cout << "FID: " << fid << endl;
After that no more cout's get called. then the game stops responding.
Thank you for reading and hopefully i was descriptive enough.
EDIT: The whole code stops the game minecraft from responding after some time or instantly idk its random.
I use standard injection with extreme injector for now.
This is some information i got from debugging:
IID: 0000000024D1FE80
INSTANCE: 00000000191813F8
LID: 0000000000000032
classLoader: 0000000019181400
FID: 0000000016176C90
#
# A fatal error has been detected by the Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x0000000002d7688e, pid=6048, tid=0x0000000000001648
#
# JRE version: Java(TM) SE Runtime Environment (8.0_92-b14) (build 1.8.0_92-b14)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.92-b14 mixed mode windows-amd64 compressed oops)
# Problematic frame:
# J 3576 C2 net.minecraft.launchwrapper.LaunchClassLoader.findClass(Ljava/lang/String;)Ljava/lang/Class; (695 bytes) # 0x0000000002d7688e [0x0000000002d76820+0x6e]
#
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# An error report file with more information is saved as:
# C:\Users\Balen\Desktop\ForgeMod\eclipse\hs_err_pid6048.log
#
# If you would like to submit a bug report, please visit:
# http://bugreport.java.com/bugreport/crash.jsp
#
AL lib: (EE) alc_cleanup: 1 device not closed
:runClient FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':runClient'.
> Process 'command 'C:\Program Files\Java\jdk1.8.0_92\bin\java.exe'' finished with non-zero exit value 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 8 mins 50.128 secs
Edit: This is to better explain everything:
I inject this dll into the game after everything in the game has initialized.
The games uses a custom class loader(LaunchClassLoader) i try to retrieve a instance of that, to do so i get the FMLLaunchHandler there i get a instanceof FMLLaunchHandler then from that instance i get classLoader and from that instance i use the classLoaders findClass to get the class.
Someone told me that i need to get a initialized version of a class to use non static methods or get non static fields.
I use a injector called extreme injector for now and use standard injection which is loadlibrary.
I also do not create my own vm, i attach to the running minecraft vm and get the env from that thru a dll and init function handles the attaching.
Thanks for reading, have nice day.
Related
Hi I was wondering if there is a way to load all the content of the guided decision table to java collection (list/map)? I achieved this by making each rule(row) calling a java method where I add this to a hashmap but performance-wise is really bad I was wondering if there is a better way to do so. Thanks in advance!
[![enter image description here]
package MyPkg;
import com.abc.por.model.Bborder;
import com.abc.por.utils.BborderUtil;
import com.abc.por.utils.MyUtil;
import com.abc.por.model.constants.FE;
//from row number: 1
//PRE_Regression
rule "Row 1 HPDT"
#RuleName(OnlyOnePharmacy)
no-loop true
lock-on-active true
ruleflow-group "HighPayer"
dialect "mvel"
when
borderUtil : BborderUtil( )
Bborder( src : src == "SPECIAL" )
border : Bborder( requestDateTime >= "24-Dec-2020" , requestDateTime < "03-May-2022" )
then
MyUtil myUtil = new MyUtil();
myUtil.setPlanCode( "RGC" );
myUtil.setPlanType( "RGC" );
myUtil.setFeIndicator( "NO" );
myUtil.setPharmacies( "RED" );
insert( myUtil );
modify( borderUtil ) {
setRuleFired( true )
}
borderUtil.populateDrugDataToMap( null, myUtil, border );
retract( myUtil);
end
//from row number: 2
//PRE_Regression
rule "Row 2 HPDT"
#RuleName(SinglePharmacy)
no-loop true
lock-on-active true
ruleflow-group "HighPayer"
dialect "mvel"
when
borderUtil : BborderUtil( )
Bborder( src : src == "SPECIAL" )
border : Bborder( requestDateTime >= "24-Dec-2020" )
then
MyUtil myUtil = new MyUtil();
myUtil.setPlanCode( "RGA" );
myUtil.setPlanType( "RGA" );
myUtil.setFeIndicator( "NO" );
myUtil.setPharmacies( "MPT,RED" );
insert( myUtil );
modify( borderUtil ) {
setRuleFired( true )
}
borderUtil.populateDrugDataToMap( null, myUtil, border );
retract( myUtil);
end
//from row number: 3
//PRE_Regression
rule "Row 3 HPDT"
#RuleName(FE=BE)
no-loop true
lock-on-active true
ruleflow-group "HighPayer"
dialect "mvel"
when
borderUtil : BborderUtil( )
Bborder( src : src == "SPECIAL" )
border : Bborder( requestDateTime >= "24-Dec-2020" )
then
MyUtil myUtil = new MyUtil();
myUtil.setPlanCode( "RGB" );
myUtil.setPlanType( "RGB" );
myUtil.setFeIndicator( "YES" );
myUtil.setPharmacies( "MPT,RED" );
insert( myUtil );
modify( borderUtil ) {
setRuleFired( true )
}
borderUtil.populateDrugDataToMap( null, myUtil, border );
retract( myUtil);
end
Kotlin Code using org.objectweb.asm library
import org.objectweb.asm.ClassWriter
import org.objectweb.asm.Opcodes.*
fun main(args: Array<String>) {
val classWriter = ClassWriter(ClassWriter.COMPUTE_MAXS)
classWriter.visit(
V1_8,
ACC_PUBLIC,
"com/github/patrick/learnasm/build/HelloWorld",
null,
"java/lang/Object",
null
)
val methodVisitor = classWriter.visitMethod(
ACC_PUBLIC + ACC_STATIC,
"main",
"([Ljava/lang/String;)V",
null,
null
)
methodVisitor.visitFieldInsn(
GETSTATIC,
"java/lang/System",
"out",
"Ljava/io/PrintStream;"
)
methodVisitor.visitLdcInsn(
"Hello World!"
)
methodVisitor.visitMethodInsn(
INVOKEVIRTUAL,
"java/io/PrintStream",
"println",
"(Ljava/lang/String;)V",
false
)
methodVisitor.visitInsn(
RETURN
)
methodVisitor.visitMaxs(
0,
0
)
methodVisitor.visitEnd()
val bytes = classWriter.toByteArray()
val clazz = defineClass(
"com.github.patrick.learnasm.build.HelloWorld",
bytes,
0,
bytes.count()
)
clazz.getDeclaredMethod("main", Array<String>::class.java).invoke(null, null)
}
I am trying to learn asm, and I'm curious whether creating a method with named parameter is possible.
For example in this case, the created class has no parameter name (defaults to var0 in decompiler), and I wish I could save parameter names like "args". Would it be possible?
Found an answer by looking into compiled class (by including debugging information)
The simple way is to just mock the compiled class
All I had to do is put some label on it, and visit local variable with name.
methodVisitor = classWriter.visitMethod(
Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC,
"main",
"([Ljava/lang/String;)V",
null,
null
)
methodVisitor.visitParameterAnnotation(
0,
"Lorg.jetbrains.annotations.NotNull;",
false
)
val start = Label()
methodVisitor.visitLabel(start)
methodVisitor.visitFieldInsn(
Opcodes.GETSTATIC,
"java/lang/System",
"out",
"Ljava/io/PrintStream;"
)
methodVisitor.visitLdcInsn("Hello World!")
methodVisitor.visitMethodInsn(
Opcodes.INVOKEVIRTUAL,
"java/io/PrintStream",
"println",
"(Ljava/lang/String;)V",
false
)
methodVisitor.visitInsn(Opcodes.RETURN)
val end = Label()
methodVisitor.visitLabel(end)
methodVisitor.visitLocalVariable(
"args",
"[Ljava/lang/String;",
null,
start,
end,
0
)
methodVisitor.visitMaxs(0, 0)
methodVisitor.visitEnd()
We've been using Esproc with our BIRT reports for a while now and everything worked perfectly. We followed this tutorial and things worked. However, the latest version of their software incorporated a couple of new functionalities and as such, we now need to upgrade the version running with BIRT. The thing is that now, nothing's working. We keep getting NullPointerException when trying to run reports. This is what we're getting so far:
The following report will be sent to Eclipse:
------
STATUS
------
pluginId org.eclipse.jface
pluginVersion 3.12.0.v20160518-1929
code 2
severity 4
message Problems occurred when invoking code from plug-in: "org.eclipse.jface".
fingerprint eb22eddc61b2abbaef12193bb7441fab
Exception:java.lang.NullPointerException: null
at com.esproc.jdbc.Server.getDfxList(Unknown Source:88)
at com.esproc.jdbc.InternalConnection.getMetaData(Unknown Source:314)
at org.eclipse.birt.report.data.oda.jdbc.ui.provider.JdbcMetaDataProvider.isSupportSchema(JdbcMetaDataProvider.java:305)
at org.eclipse.birt.report.data.oda.jdbc.ui.editors.SQLDataSetEditorPage.createDBMetaDataSelectionComposite(SQLDataSetEditorPage.java:405)
at org.eclipse.birt.report.data.oda.jdbc.ui.editors.SQLDataSetEditorPage.createPageControl(SQLDataSetEditorPage.java:334)
at org.eclipse.birt.report.data.oda.jdbc.ui.editors.SQLDataSetEditorPage.createPageCustomControl(SQLDataSetEditorPage.java:307)
at org.eclipse.datatools.connectivity.oda.design.ui.wizards.DataSetWizardPage.createControl(DataSetWizardPage.java:123)
at org.eclipse.datatools.connectivity.oda.design.internal.ui.DataSetEditorPageCore.createContents(DataSetEditorPageCore.java:74)
at org.eclipse.jface.preference.PreferencePage.createControl(PreferencePage.java:241)
at org.eclipse.birt.report.designer.data.ui.dataset.PropertyPageWrapper.createPageControl(PropertyPageWrapper.java:61)
at org.eclipse.birt.report.designer.data.ui.property.PropertyNode.createPageControl(PropertyNode.java:238)
at org.eclipse.birt.report.designer.data.ui.property.AbstractPropertyDialog.showPage(AbstractPropertyDialog.java:577)
at org.eclipse.birt.report.designer.data.ui.property.AbstractPropertyDialog.showSelectionPage(AbstractPropertyDialog.java:482)
at org.eclipse.birt.report.designer.data.ui.dataset.DataSetEditor.showSelectionPage(DataSetEditor.java:913)
at org.eclipse.birt.report.designer.data.ui.property.AbstractPropertyDialog$2$1.run(AbstractPropertyDialog.java:438)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
at org.eclipse.birt.report.designer.data.ui.property.AbstractPropertyDialog$2.selectionChanged(AbstractPropertyDialog.java:433)
at org.eclipse.jface.viewers.Viewer$1.run(Viewer.java:158)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.ui.internal.JFaceUtil$1.run(JFaceUtil.java:50)
at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:173)
at org.eclipse.jface.viewers.Viewer.fireSelectionChanged(Viewer.java:155)
at org.eclipse.jface.viewers.StructuredViewer.updateSelection(StructuredViewer.java:2191)
at org.eclipse.jface.viewers.StructuredViewer.setSelection(StructuredViewer.java:1728)
at org.eclipse.jface.viewers.TreeViewer.setSelection(TreeViewer.java:1077)
at org.eclipse.jface.viewers.Viewer.setSelection(Viewer.java:383)
at org.eclipse.birt.report.designer.data.ui.property.AbstractPropertyDialog.initTreeSelection(AbstractPropertyDialog.java:408)
at org.eclipse.birt.report.designer.data.ui.property.AbstractPropertyDialog.createDialogArea(AbstractPropertyDialog.java:299)
at org.eclipse.birt.report.designer.data.ui.dataset.DataSetEditor.createDialogArea(DataSetEditor.java:124)
at org.eclipse.jface.dialogs.Dialog.createContents(Dialog.java:767)
at org.eclipse.birt.report.designer.data.ui.dataset.DataSetEditor.createContents(DataSetEditor.java:602)
at org.eclipse.jface.window.Window.create(Window.java:426)
at org.eclipse.jface.dialogs.Dialog.create(Dialog.java:1095)
at org.eclipse.birt.report.designer.ui.dialogs.BaseDialog.open(BaseDialog.java:107)
at org.eclipse.birt.report.designer.data.ui.actions.EditDataSetAction.doAction(EditDataSetAction.java:105)
at org.eclipse.birt.report.designer.internal.ui.views.actions.AbstractElementAction.run(AbstractElementAction.java:70)
at org.eclipse.jface.action.Action.runWithEvent(Action.java:473)
at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:565)
at org.eclipse.jface.action.ActionContributionItem.lambda$4(ActionContributionItem.java:397)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4410)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1079)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4228)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3816)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$4.run(PartRenderingEngine.java:1121)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1022)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:150)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:687)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:604)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:148)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:138)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:388)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:243)
at sun.reflect.NativeMethodAccessorImpl.invoke0(null:-2)
at sun.reflect.NativeMethodAccessorImpl.invoke(null:-1)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(null:-1)
at java.lang.reflect.Method.invoke(null:-1)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:673)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:610)
at org.eclipse.equinox.launcher.Main.run(Main.java:1519)
------
REPORT
------
anonymousId 12355fbc-cb0f-41c4-b330-1d4a60fd5df2
name
email
comment
eclipseBuildId 4.6.0.I20160606-1100
eclipseProduct org.eclipse.epp.package.reporting.product
javaRuntimeVersion 1.8.0_71-b15
osgiWs win32
osgiOs Windows10
osgiOsVersion 10.0.0
osgiArch x86_64
severity UNKNOWN
-------
BUNDLES
-------
name org.eclipse.birt.report.data.oda.jdbc.ui
version 4.6.0.v201606072122
name org.eclipse.birt.report.data.oda.jdbc
version 4.6.0.v201606072122
name org.eclipse.birt
version 4.6.0.v201606072122
name org.eclipse.birt.report.designer.ui
version 4.6.0.v201606072122
name org.eclipse.birt.report.designer.ui.views
version 4.6.0.v201606072122
name org.eclipse.core.databinding.observable
version 1.6.0.v20160511-1747
name org.eclipse.core.databinding
version 1.6.0.v20160412-0910
name org.eclipse.core.runtime
version 3.12.0.v20160606-1342
name org.eclipse.datatools.connectivity.oda.design.ui
version 3.3.0.201603142002
name org.eclipse.datatools.connectivity.oda.design
version 3.4.0.201603142002
name org.eclipse.datatools.connectivity.oda
version 3.5.0.201603142002
name org.eclipse.datatools.connectivity
version 1.13.0.201603142002
name org.eclipse.e4.ui.workbench
version 1.4.0.v20160517-1624
name org.eclipse.e4.ui.workbench.swt
version 0.14.0.v20160523-1900
name org.eclipse.equinox.app
version 1.3.400.v20150715-1528
name org.eclipse.equinox.launcher
version 1.3.200.v20160318-1642
name org.eclipse.jface
version 3.12.0.v20160518-1929
name org.eclipse.swt
version 3.105.0.v20160603-0902
name org.eclipse.ui
version 3.108.0.v20160518-1929
name org.eclipse.ui.ide.application
version 1.1.100.v20160518-1929
name org.eclipse.ui.ide
version 3.12.0.v20160601-1609
Anyone has any idea what's going on?
Thanks
Okay, so I was able to actually get things working and the solution isn't exactly what I'd call trivial. I actually had to modify and recompile three BIRT classes. You can easily get the source code here if you don't want to do the Google search. Anyway, our first modification is given to us by the error message cited above. We need to alter JdbcMetaDataProvider.java located in the org.eclipse.birt.report.data.oda.jdbc.ui_4.6.0.v201606072122.jar package. What we're looking for is the isSupportSchema() method. and more specifically this bit of code:
try
{
return connection.getMetaData( ).supportsSchemasInTableDefinitions( );
}
catch ( SQLException e )
{
try
{
reconnect( );
return connection.getMetaData( ).supportsSchemasInTableDefinitions( );
}
catch ( Exception e1 )
{
try
{
ResultSet rs = connection.getMetaData( ).getSchemas( );
if( rs != null )
return true;
else
return false;
}
catch (SQLException e2)
{
logger.log( Level.WARNING, e.getMessage( ), e1 );
return false;
}
}
}
Not having access to Esproc's code, I can't exactly say why it does this, but connection.getMetaData( ).supportsSchemasInTableDefinitions( ); throws a NullPointerException. With no "catch" block to treat said exception, Eclipse will just stop its execution and prevent you from accessing your dataset. So we need to fix that like so:
try
{
return connection.getMetaData( ).supportsSchemasInTableDefinitions( );
}
catch ( SQLException e )
{
try
{
reconnect( );
return connection.getMetaData( ).supportsSchemasInTableDefinitions( );
}
catch ( Exception e1 )
{
try
{
ResultSet rs = connection.getMetaData( ).getSchemas( );
if( rs != null )
return true;
else
return false;
}
catch (SQLException e2)
{
logger.log( Level.WARNING, e.getMessage( ), e1 );
return false;
}
}
}
catch (NullPointerException e)
{
return false;
}
Now then, the next two bits of code we need to alter are located in the oda-jdbc.jar package. The first one we're looking for is the Connection.java class and more specifically the method populateConnectionProp( ).
private void populateConnectionProp( ) throws SQLException
{
if( jdbcConn!= null )
{
if( this.autoCommit != null )
jdbcConn.setAutoCommit( this.autoCommit );
else
{
if (DBConfig.getInstance().qualifyPolicy(
jdbcConn.getMetaData().getDriverName(),
DBConfig.SET_COMMIT_TO_FALSE) ) {
this.autoCommit = false;
jdbcConn.setAutoCommit( false );
}
}
if( this.isolationMode!= Constants.TRANSCATION_ISOLATION_DEFAULT)
jdbcConn.setTransactionIsolation( this.isolationMode );
}
}
This time the culprit throwing a NullPointerException is this line jdbcConn.getMetaData().getDriverName(). Again, not having access to Esproc's code, I don't really know why trying to recover the driver's name doesn't work, but anyway all we need to do is actually catch the exception and things will work normally again:
private void populateConnectionProp( ) throws SQLException
{
if( jdbcConn!= null )
{
if( this.autoCommit != null )
jdbcConn.setAutoCommit( this.autoCommit );
else
{
try
{
if (DBConfig.getInstance().qualifyPolicy(
jdbcConn.getMetaData().getDriverName(),
DBConfig.SET_COMMIT_TO_FALSE) ) {
this.autoCommit = false;
jdbcConn.setAutoCommit( false );
}
}
catch(NullPointerException e)
{
this.autoCommit = false;
jdbcConn.setAutoCommit( false );
}
}
if( this.isolationMode!= Constants.TRANSCATION_ISOLATION_DEFAULT)
jdbcConn.setTransactionIsolation( this.isolationMode );
}
}
The other class we're looking for is the CallStatement.java class. In it we're going to have to locate the getCallableParamMetaData() method that I've pasted below:
private java.util.List getCallableParamMetaData( )
{
java.util.List paramMetaDataList = new ArrayList( );
try
{
DatabaseMetaData metaData = conn.getMetaData( );
String cataLog = conn.getCatalog( );
String procedureNamePattern = getNamePattern( this.paramUtil.getProcedure( ) );
String schemaPattern = null;
if ( this.paramUtil.getSchema( ) != null )
{
schemaPattern = getNamePattern( this.paramUtil.getSchema( ) );
}
// handles schema.package.storedprocedure for databases such as
// Oracle
if ( !metaData.supportsCatalogsInProcedureCalls( ) )
{
if (this.paramUtil.getPackage( ) != null)
{
cataLog = getNamePattern( this.paramUtil.getPackage( ) );
}
}
java.sql.ResultSet rs = null;
rs = metaData.getProcedureColumns( cataLog,
schemaPattern,
procedureNamePattern,
null );
while ( rs.next( ) )
{
ParameterDefn p = new ParameterDefn( );
p.setParamName( rs.getString( "COLUMN_NAME" ) );
p.setParamInOutType( rs.getInt( "COLUMN_TYPE" ) );
p.setParamType( rs.getInt( "DATA_TYPE" ) );
p.setParamTypeName( rs.getString( "TYPE_NAME" ) );
p.setPrecision( rs.getInt( "PRECISION" ) );
p.setScale( rs.getInt( "SCALE" ) );
p.setIsNullable( rs.getInt( "NULLABLE" ) );
if ( p.getParamType( ) == Types.OTHER )
correctParamType( p );
paramMetaDataList.add( p );
}
rs.close( );
}
catch ( SQLException e )
{
logger.log( Level.SEVERE, "Fail to get SP paramters", e );
}
catch( JDBCException ex)
{
logger.log( Level.SEVERE, "Fail to get SP paramters", ex );
}
return paramMetaDataList;
}
Basically, somewhere within the while ( rs.next( ) ) loop lies the culprit throwing the NullPointerException. So all we need to do to is add a catch statement to treat it as follow:
private java.util.List getCallableParamMetaData( )
{
java.util.List paramMetaDataList = new ArrayList( );
try
{
DatabaseMetaData metaData = conn.getMetaData( );
String cataLog = conn.getCatalog( );
String procedureNamePattern = getNamePattern( this.paramUtil.getProcedure( ) );
String schemaPattern = null;
if ( this.paramUtil.getSchema( ) != null )
{
schemaPattern = getNamePattern( this.paramUtil.getSchema( ) );
}
// handles schema.package.storedprocedure for databases such as
// Oracle
if ( !metaData.supportsCatalogsInProcedureCalls( ) )
{
if (this.paramUtil.getPackage( ) != null)
{
cataLog = getNamePattern( this.paramUtil.getPackage( ) );
}
}
java.sql.ResultSet rs = null;
rs = metaData.getProcedureColumns( cataLog,
schemaPattern,
procedureNamePattern,
null );
while ( rs.next( ) )
{
ParameterDefn p = new ParameterDefn( );
p.setParamName( rs.getString( "COLUMN_NAME" ) );
p.setParamInOutType( rs.getInt( "COLUMN_TYPE" ) );
p.setParamType( rs.getInt( "DATA_TYPE" ) );
p.setParamTypeName( rs.getString( "TYPE_NAME" ) );
p.setPrecision( rs.getInt( "PRECISION" ) );
p.setScale( rs.getInt( "SCALE" ) );
p.setIsNullable( rs.getInt( "NULLABLE" ) );
if ( p.getParamType( ) == Types.OTHER )
correctParamType( p );
paramMetaDataList.add( p );
}
rs.close( );
}
catch ( SQLException e )
{
logger.log( Level.SEVERE, "Fail to get SP paramters", e );
}
catch( JDBCException ex)
{
logger.log( Level.SEVERE, "Fail to get SP paramters", ex );
}
catch( NullPointerException ex1)
{
logger.log( Level.SEVERE, "Fail to get SP paramters", ex1 );
}
return paramMetaDataList;
}
Once you've done your modifications to the files, you actually need to recompile your source code. To do this successfully, you're going to need to copy a couple of jars from Eclipse's plugin folder into the same folder as where you've placed the file you're trying to compile. The jars are given below in the command you need to enter to compile your source code. Here's what you need to enter in order to compile each file:
JdbcMetaDataProvider.java
javac -cp ".;
c:/mypath/org.eclipse.birt.report.data.bidi.utils_4.6.0.v201606072122.jar;
c:/mypath/org.eclipse.birt.report.data.oda.jdbc.ui_4.6.0.v201606072122.jar;
c:/mypath/oda-jdbc.jar;
c:/mypath/org.eclipse.datatools.connectivity.oda_3.5.0.201603142002.jar;
c:/mypath/org.eclipse.datatools.connectivity.oda.design_3.4.0.201603142002.jar;
c:/mypath/org.eclipse.datatools.connectivity.oda.design.ui_3.3.0.201603142002.jar;
c:/mypath/org.eclipse.emf.ecore_2.12.0.v20160420-0247.jar;
c:/mypath/org.eclipse.emf.common_2.12.0.v20160420-0247.jar" JdbcMetaDataProvider.java > log.txt 2>&1
Connection.java
javac -cp ".;
c:/mypath/org.eclipse.birt.report.data.bidi.utils_4.6.0.v201606072122.jar;
c:/mypath/oda-jdbc.jar;
c:/mypath/org.eclipse.datatools.connectivity.oda_3.5.0.201603142002.jar;
c:/mypath/com.ibm.icu_56.1.0.v201601250100.jar" Connection.java > log.txt 2>&1
CallStatement.java
javac -cp ".;
c:/mypath/oda-jdbc.jar;
c:/mypath/org.eclipse.datatools.connectivity.oda_3.5.0.201603142002.jar;
c:/mypath/com.ibm.icu_56.1.0.v201601250100.jar" CallStatement.java > log.txt 2>&1
Now, there's a couple of things that need to be said about the two above commands:
1) They actually need to be entered on one line. I merely broke them down like so for clarity purposes so that each jar needed was easy to spot.
2) This is actually a windows command. If you're running the command on Linux, each jar needs to be separated by a colon(:) instead of a semi-colon(;).
Once the compilation is successful, you'll end up with the following .class files:
JdbcMetaDataProvider$1TempThread.class
JdbcMetaDataProvider$2TempThread.class
JdbcMetaDataProvider.class
Connection$Constants.class
Connection.class
CallStatement.class
These need to be copied back into the original jar files so that they replace the files already there. Luckily, a jar file is nothing more than a zip file so in windows, any unzipping software will easily open things up for you and allow you to navigate to the proper folder.
Here are the the folders in question for each jar:
org\eclipse\birt\report\data\oda\jdbc\ui\provider\
org\eclipse\birt\report\data\oda\jdbc\
org\eclipse\birt\report\data\oda\jdbc\
Once that's done, restart Eclipse and things should work like normal again. I hope this helps someone in the future.
I am trying to test some methods (mainly session resumption) to IKEv.2 inside the Ipsec protocol, using Contiki OS as implemented by the Cooja simulation environment.
I need your help to assist me incorporate the session resumption protocol code in C, so that I can resume my simulation.
I tried my best to develop the code, but every time I try to run it, it always gives me the same error " reading out of memory"
I trace the error in IPsec and IKEv.2 protocol code that I download it from this like https://github.com/vjutvik/Contiki-IPsec
and found the error appear when call hmac_sha1(prf_data); function. the error message is "Reading outside memory: 0xfa8b6".
the file path of this function is: contiki-ipsec\core\net\ipsec\ike\prf.c
/**
* PRF as defined in the RFC
*/
void prf(sa_prf_transform_type_t prf_type, prf_data_t *prf_data)
{
switch (prf_type) {
case SA_PRF_HMAC_SHA1: // MUST
hmac_sha1(prf_data);
break;
case SA_PRF_AES128_CBC: // SHOULD+
PRINTF(IPSEC "Error: Not implemented\n");
break;
default:
PRINTF(IPSEC "Error: Unknown PRF request\n");
}
}
the code function hmac_sha1(prf_data);
the file path of this function is: contiki-ipsec\core\lib\hmac-sha1\hmac-sha1.c
/**
* Performs HMAC-SHA1-96. Call this function from your program.
*
* #param out Output from HMAC-SHA1-96 (must be at least 96/8=12 bytes)
* #param key The key to use
* #param keylen The length of the key
* #param data The data to hash
* #param datalen The length of the data
*/
//void hmac_sha1_96( uint16_t datalen, uint8_t * out, uint8_t * key, uint8_t keylen, uint8_t * data )
void hmac_sha1( hmac_data_t *hmac_data )
{
uint8_t * out=hmac_data->out;
uint8_t * key= (uint8_t *) hmac_data->key;
uint8_t keylen=hmac_data->keylen;
uint8_t * data=hmac_data->data;
uint16_t datalen=hmac_data->datalen;
dy_printf( "Data after %d %d %d %d %d\n", (int)out, (int)key,(int)keylen,(int)data, (int)datalen );
// Variables
uint8_t padded_key[ SHA1_B ];
uint8_t padded_key_xor_ipad[ SHA1_B ];
uint8_t sentence_a[ SHA1_B + datalen ];
uint8_t hash_output_a[ SHA1_L ];
uint8_t padded_key_xor_opad[ SHA1_B ];
uint8_t sentence_b[ SHA1_B + SHA1_L ];
uint8_t hash_output_b[ SHA1_L ];
init();
// Hash overlength keys
if( keylen > SHA1_B ){
hash_sha1( padded_key, key, keylen ); // Assumes SHA1_L <= SHA_B
create_padded_key( padded_key, padded_key, SHA1_L ); // Adds the zeros
}
else{
create_padded_key( padded_key, key, keylen );
}
dy_printf("datelen:%d\n",(int)datalen);
PRINT_BUF("padded_key",padded_key,SHA1_B);
xor_array( padded_key_xor_ipad, padded_key, ipad, SHA1_B );
PRINT_BUF("padded_key_xor_ipad",padded_key_xor_ipad,SHA1_B);
merge_arrays( sentence_a, padded_key_xor_ipad, SHA1_B, data, datalen );
PRINT_BUF("sentence_a",sentence_a,SHA1_B+datalen);
hash_sha1( hash_output_a, sentence_a, SHA1_B + datalen );
PRINT_BUF("hash_output_a",hash_output_a,SHA1_L);
xor_array( padded_key_xor_opad, padded_key, opad, SHA1_B );
PRINT_BUF("padded_key_xor_opad",padded_key_xor_opad,SHA1_B);
merge_arrays( sentence_b, padded_key_xor_opad, SHA1_B, hash_output_a, SHA1_L );
hash_sha1(hmac_data->out, sentence_b, SHA1_B + SHA1_L );
// Old truncate code
//hash_sha1( hash_output_b, sentence_b, SHA1_B + SHA1_L );
//truncate( out, hash_output_b, 96/8 );
}
I use Ubuntu 14.04 LTS 32-bit
gcc (Ubuntu 4.8.4-2ubuntu1~14.04) 4.8.4
Copyright (C) 2013 Free Software Foundation, Inc.
msp430-gcc (GCC) 4.7.2 20120920 (mspgcc dev 20120911)
Copyright (C) 2012 Free Software Foundation, Inc.
I using Contiki-IPsec 2.7 OS, also I’m using Wismote in Cooja simulation
Edit:
the type defined of the pointers in the functions above is
typedef struct {
uint8_t *out;
const uint8_t *key;
uint8_t keylen;
uint8_t *data;
uint16_t datalen;
} hmac_data_t;
and the other type defined
typedef hmac_data_t prf_data_t;
Any idea to overcome this issue is highly appreciated.
Thanking you in advanced.
I am doing some work in opengl and java/android. I have some code in c++ and am using JNI to interface between the two. I get the results:
D/App ( 2966): eglGetCurrentDisplay() 1
D/App ( 2966): thread id from c++ 2920
D/dalvikvm( 2966): threadid=11: interp stack at 0x613c5000
D/dalvikvm( 2966): init ref table
D/dalvikvm( 2966): init mutex
D/dalvikvm( 2966): create JNI env
D/dalvikvm( 2966): create fake frame
D/dalvikvm( 2966): threadid=11: adding to list (attached)
D/dalvikvm( 2966): threadid=11: attached from native, name=(null)
D/App ( 2966): thread id 2920
D/App ( 2966): EGL.eglGetCurrentDisplay is com.google.android.gles_jni.EGLDisplayImpl#0
From the code below. Which means the current display is changing when I go into JNI. Why does this happen? The thread is not changing and I believe thread local storage is where the driver will store this information.
c++ code:
printf("eglGetCurrentDisplay() %x\n", eglGetCurrentDisplay());
printf("thread id from c++ %d\n", (int)gettid());
int ret = Call_Java<int>("JNITest", "(I)I", 0 );
template<typename T>
T Call_Java(const char* sMethodName, const char* sMethodArgs, ...)
{
JavaVM *g_javaVMcached;
va_list argp;
jint res;
jobject obj;
getJavaCache(&obj, &g_javaVMcached);
assert(obj != 0);
JNIEnv * env = 0;
res = g_javaVMcached->AttachCurrentThread( &env, 0 );
assert( res == 0 && env != 0 )
jclass clazz = 0;
clazz = env->GetObjectClass( obj );
assert( clazz != 0 )
jmethodID methodID = env->GetMethodID( clazz, sMethodName, sMethodArgs ); // Name + Args
assert( methodID != 0 )
va_start(argp, sMethodArgs);
T result=0;
result = callJNIMethod<T>(obj, env, methodID, argp);
va_end(argp);
env->DeleteLocalRef( clazz );
return result;
}
template <>
int callJNIMethod(const jobject & obj, JNIEnv *env, jmethodID methodID, va_list args)
{
return env->CallIntMethodV(obj, methodID, args);
}
Java code:
int JNITest(int test)
{
Log.d(TAG, "thread id " + (int)android.os.Process.myTid());
EGLDisplay disp = EGL.eglGetCurrentDisplay();
Log.d(TAG, "EGL.eglGetCurrentDisplay is " + disp);
return 0;
}
In C++ code, the EGL display is a simple integer. In Java code, the EGL display is an object. These happen to print differently.
Android currently only defines the default display.
Aha! So I found the reason for this: I was linking against the EGL libraries in /vendor/lib/ instead of the libraries in /system/lib/.
The indicator for this was that when I called eglInitialize() I was NOT getting the following log output:
D/libEGL ( 4599): loaded /vendor/lib/egl/libEGL...
D/libEGL ( 4599): loaded /vendor/lib/egl/libGLESv1...
D/libEGL ( 4599): loaded /vendor/lib/egl/libGLESv2...
Whereas a working version should have these lines in the log output. This now gives me a correct call to eglGetCurrentDisplay() that does not give EGL_NO_DISPLAY.