/* 0xb8 invokestatic */ static int op_invokestatic(unsigned char **opCode, StackFrame *stack, SimpleConstantPool *p) { u2 method_index ; unsigned char tmp[2]; char method_name[255]; char clsName[255]; char method_type[255]; tmp[0] = opCode[0][1]; tmp[1] = opCode[0][2]; method_index = tmp[0] << 8 | tmp[1]; #if SIMPLE_JVM_DEBUG printf("invokestatic method_index %d\n", method_index); printf("simpleMethodPool.method_used = %d\n", simpleMethodPool.method_used); #endif *opCode = *opCode + 3; if (method_index < simpleMethodPool.method_used) { MethodInfo *method = &simpleMethodPool.method[method_index]; memset(method_name, 0, 255); getUTF8String(p, method->name_index, 255, method_name); #if SIMPLE_JVM_DEBUG printf(" method name = %s\n", method_name); #endif } else { ConstantMethodRef *mRef = findMethodRef(p, method_index); if (mRef != 0) { ConstantClassRef *clasz = findClassRef(p, mRef->classIndex); ConstantNameAndType *nat = findNameAndType(p, mRef->nameAndTypeIndex); if (clasz == 0 || nat == 0) return -1; getUTF8String(p, clasz->stringIndex, 255, clsName); getUTF8String(p, nat->nameIndex, 255, method_name); getUTF8String(p, nat->typeIndex, 255, method_type); #if SIMPLE_JVM_DEBUG printf("call class %s\n", clsName); printf("call method %s\n", method_name); printf("call method type %s\n", method_type); int ret = #endif invoke_java_lang_library(stack, p, clsName, method_name, method_type); #if SIMPLE_JVM_DEBUG if (ret) { printf("invoke java lang library successful\n"); } #endif } } return 0; }
static void printCodeAttribute(CodeAttribute *ca, SimpleConstantPool *p) { int i = 0; int tmp = 0; char name[255]; getUTF8String(p, ca->attribute_name_index, 255, name); printf("attribute name : %s\n", name); printf("attribute length: %d\n", ca->attribute_length); printf("max_stack: %d\n", ca->max_stack); printf("max_locals: %d\n", ca->max_locals); printf("code_length: %d\n", ca->code_length); unsigned char *pc = ca->code; i = 0; do { char *opName = findOpCode(pc[0]); if (opName == 0) { printf("Unknow OpCode %02X\n", pc[0]); exit(1); } printf("%s \n", opName); tmp = findOpCodeOffset(pc[0]); pc += tmp; i += tmp; } while (i < ca->code_length); }
int executeMethod(MethodInfo *startup, StackFrame *stack, SimpleConstantPool *p) { int i = 0; int j = 0; char name[255]; CodeAttribute ca; memset(&ca, 0 , sizeof(CodeAttribute)); for (j = 0 ; j < startup->attributes_count ; j++) { convertToCodeAttribute(&ca, &startup->attributes[j]); getUTF8String(p, ca.attribute_name_index, 255, name); if (memcmp(name, "Code", 4) != 0) continue; #if SIMPLE_JVM_DEBUG printf("----------------------------------------\n"); printf("code dump\n"); printCodeAttribute(&ca, p); printf("----------------------------------------\n"); #endif unsigned char *pc = ca.code; if (run == 0) exit(1); do { #if 1 opCodeFunc func = findOpCodeFunc(pc[0]); if (func != 0) { i = func(&pc , &stackFrame, p); } if (i < 0) break; #endif } while (1); } return 0; }
bool AP_Win32App::initialize(void) { bool bSuccess = true; const char * szUserPrivateDirectory = getUserPrivateDirectory(); bool bVerified = s_createDirectoryIfNecessary(szUserPrivateDirectory); UT_return_val_if_fail (bVerified, false); // create templates directory UT_String sTemplates = szUserPrivateDirectory; sTemplates += "/templates"; s_createDirectoryIfNecessary(sTemplates.c_str()); // load the preferences. m_prefs = new AP_Win32Prefs(); UT_return_val_if_fail (m_prefs, false); m_prefs->fullInit(); // now that preferences are established, let the xap init m_pClipboard = new AP_Win32Clipboard(); UT_return_val_if_fail (m_pClipboard, false); m_pEMC = AP_GetEditMethods(); UT_return_val_if_fail (m_pEMC, false); m_pBindingSet = new AP_BindingSet(m_pEMC); UT_return_val_if_fail (m_pBindingSet, false); m_pMenuActionSet = AP_CreateMenuActionSet(); UT_return_val_if_fail (m_pMenuActionSet,false); m_pToolbarActionSet = AP_CreateToolbarActionSet(); UT_return_val_if_fail (m_pToolbarActionSet,false); ////////////////////////////////////////////////////////////////// // load the dialog and message box strings ////////////////////////////////////////////////////////////////// { // assume we will be using the builtin set (either as the main // set or as the fallback set). AP_BuiltinStringSet * pBuiltinStringSet = new AP_BuiltinStringSet(this,AP_PREF_DEFAULT_StringSet); UT_return_val_if_fail (pBuiltinStringSet, false); m_pStringSet = pBuiltinStringSet; // see if we should load an alternate set from the disk const char * szDirectory = NULL; const char * szStringSet = NULL; if ( (getPrefsValue(AP_PREF_KEY_StringSet,&szStringSet)) && (szStringSet) && (*szStringSet) && (g_ascii_strcasecmp(szStringSet,AP_PREF_DEFAULT_StringSet) != 0)) { getPrefsValueDirectory(true,AP_PREF_KEY_StringSetDirectory,&szDirectory); UT_return_val_if_fail ((szDirectory) && (*szDirectory), false); char * szPathname = (char *)UT_calloc(sizeof(char),strlen(szDirectory)+strlen(szStringSet)+100); UT_return_val_if_fail (szPathname, false); sprintf(szPathname,"%s%s%s.strings", szDirectory, ((szDirectory[strlen(szDirectory)-1]=='\\') ? "" : "\\"), szStringSet); AP_DiskStringSet * pDiskStringSet = new AP_DiskStringSet(this); UT_return_val_if_fail (pDiskStringSet, false); if (pDiskStringSet->loadStringsFromDisk(szPathname)) { pDiskStringSet->setFallbackStringSet(m_pStringSet); m_pStringSet = pDiskStringSet; UT_Language_updateLanguageNames(); UT_DEBUGMSG(("Using StringSet [%s]\n",szPathname)); } else { UT_DEBUGMSG(("Unable to load StringSet [%s] -- using builtin strings instead.\n",szPathname)); DELETEP(pDiskStringSet); } g_free(szPathname); } } // AP_App::initilize() calls for us XAP_Win32App::initialize() if (! AP_App::initialize()) return false; // let various window types register themselves if (!AP_Win32Frame::RegisterClass(this)) { UT_DEBUGMSG(("couldn't register class\n")); return false; } ////////////////////////////////////////////////////////////////// // Initialize the importers/exporters ////////////////////////////////////////////////////////////////// IE_ImpExp_RegisterXP (); ////////////////////////////////////////////////////////////////// // initializes the spell checker. ////////////////////////////////////////////////////////////////// { #if ENABLE_SPELL SpellManager::instance(); #endif } // Now we have the strings loaded we can populate the field names correctly int i; for (i = 0; fp_FieldTypes[i].m_Type != FPFIELDTYPE_END; i++) { (&fp_FieldTypes[i])->m_Desc = m_pStringSet->getValue(fp_FieldTypes[i].m_DescId); UT_DEBUGMSG(("Setting field type desc for type %d, desc=%s\n", fp_FieldTypes[i].m_Type, fp_FieldTypes[i].m_Desc)); } for (i = 0; fp_FieldFmts[i].m_Tag != NULL; i++) { (&fp_FieldFmts[i])->m_Desc = m_pStringSet->getValue(fp_FieldFmts[i].m_DescId); UT_DEBUGMSG(("Setting field desc for field %s, desc=%s\n", fp_FieldFmts[i].m_Tag, fp_FieldFmts[i].m_Desc)); } /////////////////////////////////////////////////////////////////////// /// Build a labelset so the plugins can add themselves to something /// /////////////////////////////////////////////////////////////////////// const char * szMenuLabelSetName = NULL; if (getPrefsValue( AP_PREF_KEY_StringSet, (const gchar**)&szMenuLabelSetName) && (szMenuLabelSetName) && (*szMenuLabelSetName)) { ; } else szMenuLabelSetName = AP_PREF_DEFAULT_StringSet; getMenuFactory()->buildMenuLabelSet(szMenuLabelSetName); ////////////////////////////////////////////////////////////////// // Check for necessary DLLs now that we can do localized error messages ////////////////////////////////////////////////////////////////// // Ensure that common control DLL is loaded HINSTANCE hinstCC = LoadLibraryW(L"comctl32.dll"); UT_return_val_if_fail (hinstCC, false); InitCommonControlsEx_fn pInitCommonControlsEx = NULL; if( hinstCC != NULL ) pInitCommonControlsEx = (InitCommonControlsEx_fn)GetProcAddress( hinstCC, "InitCommonControlsEx"); if( pInitCommonControlsEx != NULL ) { INITCOMMONCONTROLSEX icex; icex.dwSize = sizeof(INITCOMMONCONTROLSEX); icex.dwICC = ICC_COOL_CLASSES | ICC_BAR_CLASSES // load the rebar and toolbar | ICC_TAB_CLASSES | ICC_UPDOWN_CLASS // and tab and spin controls | ICC_STANDARD_CLASSES; pInitCommonControlsEx(&icex); } else { InitCommonControls(); UT_Win32LocaleString err; err.fromUTF8 (m_pStringSet->getValue(AP_STRING_ID_WINDOWS_COMCTL_WARNING)); MessageBoxW(NULL, err.c_str(), NULL, MB_OK); } ////////////////////////////////////////////////////////////////// // load the all Plugins from the correct directory ////////////////////////////////////////////////////////////////// #ifndef DISABLE_BUILTIN_PLUGINS abi_register_builtin_plugins(); #endif bool bLoadPlugins = true; bool bFound = getPrefsValueBool(XAP_PREF_KEY_AutoLoadPlugins,&bLoadPlugins); if(bLoadPlugins || !bFound) { WCHAR szPath[PATH_MAX]; WCHAR szPlugin[PATH_MAX]; _getExeDir( szPath, PATH_MAX); #ifdef _MSC_VER lstrcatW(szPath, L"..\\plugins\\*.dll"); #else #define ABI_WIDE_STRING(t) L ## t lstrcatW(szPath, ABI_WIDE_STRING("..\\lib\\" PACKAGE L"-" ABIWORD_SERIES L"\\plugins\\*.dll")); #endif WIN32_FIND_DATAW cfile; HANDLE findtag = FindFirstFileW( szPath, &cfile ); if( findtag != INVALID_HANDLE_VALUE ) { do { _getExeDir( szPlugin, PATH_MAX ); #ifdef _MSC_VER lstrcatW( szPlugin, L"..\\plugins\\" ); #else lstrcatW( szPlugin, ABI_WIDE_STRING("..\\lib\\" PACKAGE L"-" ABIWORD_SERIES L"\\plugins\\" )); #endif lstrcatW( szPlugin, cfile.cFileName ); XAP_ModuleManager::instance().loadModule( getUTF8String(szPlugin) ); } while( FindNextFileW ( findtag, &cfile ) ); FindClose( findtag ); } UT_String pluginName( getUserPrivateDirectory() ); UT_String pluginDir( getUserPrivateDirectory() ); pluginDir += "\\AbiWord\\plugins\\*.dll"; UT_Win32LocaleString str; str.fromUTF8(pluginDir.c_str()); findtag = FindFirstFileW( str.c_str(), &cfile ); if( findtag != INVALID_HANDLE_VALUE ) { do { pluginName = getUserPrivateDirectory(); pluginName += "\\AbiWord\\plugins\\"; pluginName += getUTF8String(cfile.cFileName); XAP_ModuleManager::instance().loadModule( pluginName.c_str() ); } while( FindNextFileW( findtag, &cfile ) ); FindClose( findtag ); } } return bSuccess; }
/**************************************************************************** Desc: ****************************************************************************/ JNIEXPORT jlong JNICALL Java_xflaim_Backup__1backup( JNIEnv * pEnv, jobject, // obj, jlong lThis, jstring sBackupPath, jstring sPassword, jobject backupClient, jobject backupStatus) { RCODE rc = NE_XFLM_OK; IF_Backup * pBackup = THIS_BACKUP(); FLMUINT uiSeqNum = 0; JavaVM * pJvm; JNIBackupClient * pClient = NULL; JNIBackupStatus * pStatus = NULL; FLMBYTE ucBackupPath [F_PATH_MAX_SIZE]; F_DynaBuf backupPathBuf( ucBackupPath, sizeof( ucBackupPath)); FLMBYTE ucPassword [100]; F_DynaBuf passwordBuf( ucPassword, sizeof( ucPassword)); if (RC_BAD( rc = getUTF8String( pEnv, sBackupPath, &backupPathBuf))) { ThrowError( rc, pEnv); goto Exit; } if (RC_BAD( rc = getUTF8String( pEnv, sPassword, &passwordBuf))) { ThrowError( rc, pEnv); goto Exit; } flmAssert( backupClient); pEnv->GetJavaVM( &pJvm); if( (pClient = f_new JNIBackupClient( backupClient, pJvm)) == NULL) { rc = RC_SET( NE_XFLM_MEM); ThrowError( rc, pEnv); goto Exit; } if (backupStatus) { if( (pStatus = f_new JNIBackupStatus( backupStatus, pJvm)) == NULL) { rc = RC_SET( NE_XFLM_MEM); ThrowError( rc, pEnv); goto Exit; } } if (RC_BAD( rc = pBackup->backup( (const char *)(backupPathBuf.getDataLength() > 1 ? (const char *)backupPathBuf.getBufferPtr() : (const char *)NULL), (const char *)(passwordBuf.getDataLength() > 1 ? (const char *)passwordBuf.getBufferPtr() : (const char *)NULL), pClient, pStatus, &uiSeqNum))) { ThrowError( rc, pEnv); goto Exit; } Exit: if (pClient) { pClient->Release(); } if (pStatus) { pStatus->Release(); } return( uiSeqNum); }
/* invokevirtual */ static int op_invokevirtual(unsigned char **opCode, StackFrame *stack, SimpleConstantPool *p) { u2 object_ref; unsigned char tmp[2]; char clsName[255]; char utf8[255]; int len = 0; tmp[0] = opCode[0][1]; tmp[1] = opCode[0][2]; object_ref = tmp[0] << 8 | tmp[1]; #if SIMPLE_JVM_DEBUG printf("call object_ref %d\n", object_ref); #endif *opCode = *opCode + 3; ConstantMethodRef *mRef = findMethodRef(p, object_ref); if (mRef != 0) { ConstantClassRef *clasz = findClassRef(p, mRef->classIndex); ConstantNameAndType *nat = findNameAndType(p, mRef->nameAndTypeIndex); if (clasz == 0 || nat == 0) return -1; getUTF8String(p, clasz->stringIndex, 255, clsName); #if SIMPLE_JVM_DEBUG printf("call object ref class %s\n", clsName); #endif if (strcmp(clzNamePrint, clsName) == 0) { StackEntry *entry = popEntry(stack); int index = EntryToInt(entry); #if SIMPLE_JVM_DEBUG printf("call Println with index = %d\n", index); #endif if (entry->type == STACK_ENTRY_REF) { ConstantStringRef *strRef = findStringRef(p, index); if (strRef != 0) { getUTF8String(p, strRef->stringIndex, 255, utf8); len = strlen(utf8); memcpy(stringBuilderBuffer + stringBuilderUsed, utf8, len); stringBuilderUsed += len; stringBuilderBuffer[stringBuilderUsed] = 0; } } else if (entry->type == STACK_ENTRY_INT) { sprintf(utf8, "%d", index); len = strlen(utf8); memcpy(stringBuilderBuffer + stringBuilderUsed, utf8, len); stringBuilderUsed += len; stringBuilderBuffer[stringBuilderUsed] = 0; } // printf out the result printf("%s\n", stringBuilderBuffer); memset(stringBuilderBuffer, 0, 1024); stringBuilderUsed = 0; } else if (strcmp(clzNameStrBuilder, clsName) == 0) { StackEntry *entry = popEntry(stack); int index = EntryToInt(entry); #if SIMPLE_JVM_DEBUG printf("call StringBuilder with index = %d\n", index); #endif if (entry->type == STACK_ENTRY_REF) { ConstantStringRef *strRef = findStringRef(p, index); if (strRef != 0) { getUTF8String(p, strRef->stringIndex, 255, utf8); len = strlen(utf8); memcpy(stringBuilderBuffer + stringBuilderUsed, utf8, len); stringBuilderUsed += len; } } else if (entry->type == STACK_ENTRY_INT) { sprintf(utf8, "%d", index); len = strlen(utf8); memcpy(stringBuilderBuffer + stringBuilderUsed, utf8, len); stringBuilderUsed += len; #if SIMPLE_JVM_DEBUG printf("%s\n", stringBuilderBuffer); #endif } } } return 0; }